Subscript out of range error

Garrek

Board Regular
Joined
Aug 22, 2019
Messages
53
I'm trying to copy data in Cell F33 on one workbook to cell B5 on another workbook. Whenever I run the code, I get "subscript out of range" and the debugger highlights the 6th line, containing the copy range.

Code:
Sub Copy()


Dim x As Workbook
Dim y As Workbook


Set x = Workbooks.Open("Report")
Set y = Workbooks.Open("Output")


x.Sheets("Leader").Range("F33").Copy


y.Sheets("Shell").Range("B5").PasteSpecial


End Sub

Any thoughts on why this is happening?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Do you have a sheet called "Leader" in workbook "Report"?
If so check for leading/trailing spaces in the sheet name
 
Upvote 0
Do you have a sheet called "Leader" in workbook "Report"?
If so check for leading/trailing spaces in the sheet name

I do, and I've tried renaming it multiple times. There don't appear to be any extraneous spaces either.
 
Upvote 0
If you try
Code:
Sub Copy()


Dim x As Workbook
Dim y As Workbook


Set x = Workbooks.Open("Report")
Set y = Workbooks.Open("Output")

x.Activate
Sheets("Leader").Select




End Sub
What happens?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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