我有一个工作簿( .xlsx ),其中包含销售数据(包含近50-60个工作表(Sales_2018_JAN,Sales_2018_FEB等)
我正在使用以下脚本来获取数据(在工作簿中)
Sub CopyData()
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim i As Long
With ThisWorkbook
Worksheets("REVIEW_SHEET").Activate
Set SourceSheet = Worksheets(Range("D2").Value2)
Set TargetSheet = Worksheets("REVIEW_SHEET")
End With
LastRow = SourceSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
LastCol = SourceSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
For i = 1 To LastRow
For j = 1 To LastCol
SourceSheet.Cells(i, j).Copy Destination:=TargetSheet.Cells(i + 9, j)
Next j
Next i
End Sub
如何将数据传输/复制到另一个工作簿(将其称为目标文件,该文件将为 .xlsm )。 “工作表名称”的选择将输入到单元格中(目标文件,单元格引用B2)。复制的数据应从ROW 50开始出现。
我尝试了Set TargetSheet = anotherworkbook.Worksheets("REVIEW_SHEET")
,但没有成功。请帮助我,需要什么更正。
我尝试使用下面的代码以工作表名称(目标文件单元格值)为标准,将数据从一个工作簿(.xlsx)传输/复制到另一工作簿(.xlsm)。
Sub CopyData()
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim i As Long
With ThisWorkbook
Worksheets("Summary_Test").Activate
Set SourceSheet = Worksheets(Range("D2").Value2)
Set TargetSheet = ThisWorkbook.Worksheets("Summary_Test")
End With
LastRow = SourceSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
LastCol = SourceSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
For i = 1 To LastRow
For j = 1 To LastCol
SourceSheet.Cells(i, j).Copy Destination:=TargetSheet.Cells(i + 9, j)
Next j
Next i
End Sub
我是脚本初学者。请帮我。预先谢谢!。
作为参考,两个屏幕截图均已随附。
谢谢!