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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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