-1

I am trying to have my vba code select a range from work and paste the select in a different workbook. However I get an error 1004 on the selection of the book in which to paste on. Here is my code:

Sub selectionTest()


Worksheets("Deot").Range("A1:N250").Select
Worksheets("Deot").Range("A1:N250").Copy
Worksheets("Data").Range("A1").Select
Worksheets("Data").Range("A1").Paste

End Sub

I have several tabs in the file that I wish to copy into the tab Data, please help.

YowE3K
  • 23,852
  • 7
  • 26
  • 40
JS Bach
  • 83
  • 1
  • 5
  • 15
  • https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros/10718179#10718179 This reference shows you how (and why) to avoid select – RGA Aug 01 '17 at 22:04

1 Answers1

5

You can't Select a range on an inactive worksheet - you either need to activate the sheet first or, better still, not use Select:

Sub selectionTest()
    Worksheets("Deot").Range("A1:N250").Copy Worksheets("Data").Range("A1")    
End Sub
YowE3K
  • 23,852
  • 7
  • 26
  • 40