[英]Copy data from excel sheet to another using macro
I have a sheet Rolling Plan in copy.xls worksheet.I want to copy it to Book1.xls worksheet in Sheet NO1 in Range A1:H6 我在copy.xls工作表中有一个工作表滚动计划,我想将其复制到范围A1:H6的NO1工作表中的Book1.xls工作表中
The macro in Book.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
End Sub 结束子
This does the following: 这将执行以下操作:
1) Open copy.xls
and copy data in range B6:H6
1)打开copy.xls
并复制范围B6:H6
2) Pastes the data into workbook Book1
in range A1:H6
on sheet NO1
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
Note that I am not quite sure why the data range you are copying to (ie A1:H6
) is much larger than the actual copied range (ie B6:H6
). 请注意,我不太确定为什么要复制到的数据范围(即A1:H6
)比实际复制的范围(即B6:H6
)大得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.