![](/img/trans.png)
[英]How can I copy data from one sheet to another sheet in Excel 2007 using a macro?
[英]Copy data from excel sheet to another using macro
我在copy.xls工作表中有一個工作表滾動計划,我想將其復制到范圍A1:H6的NO1工作表中的Book1.xls工作表中
Book.xls中的宏
Sub CopytoPS()
Dim sfil As String
Dim owbk As Workbook
Dim sPath As String
sPath = "C:\Users\Nirmala\Desktop\website" 'Change the file path for your purposes
sfil = Dir(sPath & "copy.xls")
Range("B6:H6").Copy
Set owbk = Workbooks.Open(sPath & sfil)
owbk.Sheets("RollinPlan").Range("B6:H6").End(xlUp).Offset(1, 0).
PasteSpecial xlPasteValues
owbk.Close True 'Save opened workbook and close
sfil = Dir
結束子
這將執行以下操作:
1)打開copy.xls
並復制范圍B6:H6
2)將數據粘貼到表NO1
上A1:H6
范圍的工作簿Book1
中
Sub CopyData()
Dim filePath As String, wb As Workbook
filePath = "C:\Users\Nirmala\Desktop\website" 'Change the file path for your purposes
Set wb = Workbooks.Open(Filename:=filePath & "\" & "copy.xls")
wb.Worksheets("Rolling Plan").Range("B6:H6").Copy Destination:=ThisWorkbook.Worksheets("NO1").Range("A1:H6")
wb.Close
End Sub
請注意,我不太確定為什么要復制到的數據范圍(即A1:H6
)比實際復制的范圍(即B6:H6
)大得多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.