robertmwaring2
Board Regular
- Joined
- Mar 8, 2019
- Messages
- 132
- Office Version
- 365
- Platform
- Windows
Hello,
I am trying to copy data into a workbook (thisworkbook) from 2 different workbooks (closedbook1, closedbook2) into 2 sheets in this workbook ("Imported Data", "Group Data").
While still relatively new to VBA, I have learned quite a bit but cannot for the life of me figure out what I am doing wrong with the following code:
When I debug the code after the error, it states this is the error:
lcol = ActiveWorkbook.Worksheets(1).Range("A6").End(xlToRight).col
I have tried every conceivable combination of ways to write this but nothing seems to make a difference. (ie, closedbook1.sheet1, activeworkbook.sheet1, activeworkbook.sheets("Property"), etc . . . )
Can someone tell me what I am doing wrong?
Thanks for your time and help (in advance)
I am trying to copy data into a workbook (thisworkbook) from 2 different workbooks (closedbook1, closedbook2) into 2 sheets in this workbook ("Imported Data", "Group Data").
While still relatively new to VBA, I have learned quite a bit but cannot for the life of me figure out what I am doing wrong with the following code:
VBA Code:
Dim closedBook1 As Workbook, closedbook2 As Workbook, lrow As Integer, lcol As Integer
Set closedBook1 = Workbooks.Open("G:\Forecast\Attachments (DO NOT DELETE!)\HOUGH Daily Data.xlsx")
lcol = ActiveWorkbook.Worksheets(1).Range("A6").End(xlToRight).col
lrow = ActiveWorkbook.Worksheets(1).Range("A6").End(xlDown).Row - 1
closedBook1.sheet1.Range(Cells(6, 1), Cells(lrow, lcol)).Copy
ThisWorkbook.Sheets("Imported Data").Range("A1").PasteSpecial xlValues
Application.CutCopyMode = False
closedBook1.Close SaveChanges:=False
Set closedbook2 = Workbooks.Open("G:\Forecast\Attachments (DO NOT DELETE!)\HOUGH Group Pick Up.xlsx")
lcol = ActiveWorkbook.Worksheets(1).Range("A13").End(xlToRight).col
lrow = ActiveWorkbook.Worksheets(1).Range("A13").End(xlDown).Row - 1
closedbook2.sheet1.Range(Cells(13, 1), Cells(lrow, lcol)).Copy
ThisWorkbook.Sheets("Group Data").Range("A1").PasteSpecial xlValues
Application.CutCopyMode = False
closedbook2.Close SaveChanges:=False
When I debug the code after the error, it states this is the error:
lcol = ActiveWorkbook.Worksheets(1).Range("A6").End(xlToRight).col
I have tried every conceivable combination of ways to write this but nothing seems to make a difference. (ie, closedbook1.sheet1, activeworkbook.sheet1, activeworkbook.sheets("Property"), etc . . . )
Can someone tell me what I am doing wrong?
Thanks for your time and help (in advance)