0

I have tried to copy Range A1:D7 from Excel_1 to Excel_2 It says Run-time error'9' subscript out of range. What's wrong with it? Both Excels are located at my onedrive.

Option Explicit
Sub copy()
Workbooks("Excel_1.xlsx").Worksheets("Sheet1").Range("A1:D7").copy _
Workbooks("Excel_2.xlsm").Worksheets("Sheet1").Range("A1")
Whiteli3
  • 11
  • 1
  • Are both files open? Do both files have a sheet named Sheet1? – BigBen Oct 04 '22 at 13:20
  • 2
    this is not your problem, but one should not use words that are also current vba functions as their sub names. I would change `Sub copy()` to something like `Sub MyCopy()` just to avoid confusion. – Scott Craner Oct 04 '22 at 13:22
  • That should work as is. You can try doing it a few different ways. See the link below for more ideas of how to do this kind of thing. https://stackoverflow.com/questions/19351832/copy-from-one-workbook-and-paste-into-another – ASH Oct 05 '22 at 16:28
  • @BigBen Only Excel_1 was open. – Whiteli3 Oct 07 '22 at 07:16
  • @ScottCraner Good point, i will change it! – Whiteli3 Oct 07 '22 at 07:18
  • @ASH Thanks, the link you posted is perfect! – Whiteli3 Oct 07 '22 at 07:39

0 Answers0