"Subscript out of range" while pasting data to another workbook

dabon

New Member
Joined
Oct 9, 2022
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I do not understand while this does not work

Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy _
Workbooks("Reports.xlsm").Worksheets("Data").Range("A2")


The "run time error 9 / Subscript out of range" message is shown. It seems that it losts the data just copied while executing the second part of the code row "Workbooks("Reports.xlsm").Worksheets("Data").Range("A2")" because it moves to the second workbook (Reports). Both workbooks are open while executing the code.

This does not happen executing this code remaining to the same workbook.

Workbooks("New Data.xlsx").Worksheets("Export").Range("A2:D9").Copy _
Workbooks("New Data.xlsx").Worksheets("Sheet1").Range("A2")


Thanks for your help
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I suspect a misspelling of either the workbook name or the sheet name. Extra/trailing spaces are often the culprit.

Is New Data a workbook that was created earlier in the macro or does it exist already when RUN is pressed?
 
Upvote 0
Sorry.. my fault! A stupid error. 😓
Thanks for the support
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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