Error on copy from one workbook to another

Milan Cetic

New Member
Joined
Oct 9, 2020
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
I'm trying to copy cells from one workbook to another (copyfrom.xslm and copyto.xlsx)
This is the code I'm using

Sub CopyToWorkbook()

Range("A1:D4").Copy Workbooks("copyto").Worksheets("Sheet1").Range("A5")

End Sub

When I execute the code I get the Runtime error '9': Subscript out of range.
It's like there is no copyto file although it is open. Makes no sense but this is what's happening. Any ideas?

Thanks!
 

Attachments

  • 2020-10-09 20_55_22-Microsoft Visual Basic for Applications - Copyfrom.xlsm - [Module1 (Code)].png
    2020-10-09 20_55_22-Microsoft Visual Basic for Applications - Copyfrom.xlsm - [Module1 (Code)].png
    37.9 KB · Views: 7

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.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub CopyToWorkbook()

Workbooks("copyfrom.xlsm").Sheets("Sheet1").Range("A1:D4").Copy Workbooks("copyto.xlsx").Worksheets("Sheet1").Range("A5")

End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub CopyToWorkbook()

Workbooks("copyfrom.xlsm").Sheets("Sheet1").Range("A1:D4").Copy Workbooks("copyto.xlsx").Worksheets("Sheet1").Range("A5")

End Sub
Tried that as well, same result.
 
Upvote 0
Oops, it should have been
VBA Code:
Sub CopyToWorkbook()

Workbooks("copyfrom.xlsm").Sheets("Test1").Range("A1:D4").Copy Workbooks("copyto.xlsx").Worksheets("Sheet1").Range("A5")

End Sub
 
Upvote 0
Tried that and it's not working.
I have even tried this:
Workbooks("copyto").Worksheets("Sheet1").Range("A1").Value = 1 (also with extension and full path)

End I get the same error message. It looks like VBA can't "see" any other file. I have also checked that all files have "Full control" permissions
 
Upvote 0
Are both workbooks open, when you run the code?
Check that the sheet names don't have any leading/trailing spaces.
 
Upvote 0
Check and check. Both workbooks open. No trailing/leading spaces. Copied full path from File explorer.
 
Upvote 0
Do not use the full path, if the workbook & sheet names are as per you image, just use the code from post#5
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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