0
我正在從一個工作簿中複製一組單個列並將它們粘貼到另一個列上。我想抵消我的數據被複制到哪一行(例如向下9行)。我試圖使用屬性:使用VBA偏移各個複製列
.Offset()
但我不知道如何將它添加到我現有的代碼。
Sub T1()
Dim sourceTitle As Range, targetTitle As Range
Set sourceTitle = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("B")
Set targetTitle = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("C")
Set sourceProject = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("C")
Set targetProject = Workbooks("Data
Destination.xlsm").Worksheets(1).Columns("D")
Set sourcePM = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("D")
Set targetPM = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("I")
Set sourceBusiness = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("E")
Set targetBusiness = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("K")
Set sourceHigh = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("F")
Set targetHigh = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("L")
Set sourceE0 = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("G")
Set targetE0 = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("S")
Set sourceActual = Workbooks("Data to Copy.xlsm").Worksheets(2).Columns("H")
Set targetActual = Workbooks("Data Destination.xlsm").Worksheets(1).Columns("V")
sourceTitle.Copy Destination:=targetTitle
sourceProject.Copy Destination:=targetProject
sourcePM.Copy Destination:=targetPM
sourceBusiness.Copy Destination:=targetBusiness
sourceHigh.Copy Destination:=targetHigh
sourceE0.Copy Destination:=targetE0
sourceActual.Copy Destination:=targetActual
End Sub
您無法偏移全列參考的行。你將需要找到數據的最後一行,限制你的範圍,然後你可以使用偏移量。 –
Offset的格式通常是這樣的:'Range(「B1」).Offset(9,0)= Value'其中9是行而0是列。 – Mitch