Requirement: I need to copy 1 Column - Col G (need to determine the number of rows dynamically) from 1 Workbook to another.
Problem: Getting VBA Error:
Runtime Error: 9 - Subscript out of range Please help.
Sub Set_Open_ExistingWorkbook()
Dim wkb As Workbook
Set wkb = Workbooks.Open("C:\Users\me364167\Documents\Practice_OB_Status_Detailed_Report_Mainframe.xls")
'Set wkb = Workbooks.Open("C:\Users\me364167\Documents\Practice level_Opportunity Pipeline_Mainframe.xls")
Dim LastRow As Long
Dim Sheet1Data As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "G").End(xlUp).Row
End With
Workbooks("Practice_OB_Status_Detailed_Report_Mainframe.xls").Worksheets("OB_Status_Detailed_Report").Range(Cells(1, "G"), Cells(LastRow, "G")).Copy
Workbooks("OB Macro.xlsx").Worksheets("OB_Status_Detailed_Report").Range(Cells(1, "A"), Cells(LastRow, "A")).PasteSpecial
' Workbooks("Practice_OB_Status_Detailed_Report_Mainframe.xls").Worksheets("OB_Status_Detailed_Report").Range(Cells(1, "G"), Cells(LastRow, "G")).Copy
' Workbooks("OB Macro.xlsx").Worksheets("OB_Status_Detailed_Report").Range(Cells(1, "A"), Cells(LastRow, "A")).PasteSpecial Paste:=xlValues
wkb.Close
End Sub
ActiveSheet
when searching for youLastRow
, instead use referenced objects, likeWith wkb.Worksheets("OB_Status_Detailed_Report")
. You are missing one parameter after the line withPasteSpecial
, you need to add something likePasteSpecial xlValues
– Shai Rado