Runtime error 438 when working with 2 workbooks

robertmwaring2

Board Regular
Joined
Mar 8, 2019
Messages
132
Office Version
  1. 365
Platform
  1. 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:

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)
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
thank you so much for looking it over for me. I appreciate the help!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top