Please check Copy Paste Code?

22strider

Active Member
Joined
Jun 11, 2007
Messages
311
Hello Friends

Could some one please check what is wrong with the following code; I am getting error message that script is out of range


Workbooks(strSourceFile).Sheets("DataSheet").Range("A1:G1").Copy Workbooks(strFileName).Worksheets("Sheet1").Range("A1")


strSourceFile and strFileName are variable file names declated as strings.

This line is part of a larger code that I am trying to make work. I did not post the complete code because I thought that would be confusing. As you may see from the code that I am trying to copy first row (Columns A to G) from the workbook strSourceFile and paste it to another workbook strFileName.

In the code both the variables (strSourceFile and strFileName) have complete path for the files.

Thanks for your time
Rajesh
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I think you're missing a destination
change
Workbooks(strSourceFile).Sheets("DataSheet").Range("A1:G1").Copy Workbooks(strFileName).Worksheets("Sheet1").Range("A1")
to
Workbooks(strSourceFile).Sheets("DataSheet").Range("A1:G1").Copy Destination:=Workbooks(strFileName).Worksheets("Sheet1").Range("A1")
 
Upvote 0
Hi

Thanks for your message. Adding "Destination" did not fix it; the same error message still appears. I'll keep debugging; if I find somehting I'll post it.

Thanks again
Rajesh
 
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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