VBA copying wrong

aba

New Member
Joined
Jun 15, 2011
Messages
4
I have a file that has two sheets of data (one continued from the next). I use the following code to copy data from sheet one onto the worksheet:

Range("A1:M65535").Select
Selection.Copy
Windows("PlanView_Data_Extract.xlsm").Activate
Sheets("Q1 & Q2 2011").Select
ActiveSheet.Paste

However, when I copy, it automatically copies data from Sheet 2 (the continuation) onto another sheet on this worksheet. Why does this happen even though a limited range (ie. A1:M65535) is selected?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Does this fare any better

Code:
Range("A1:M65535").Copy Destination:=Worksheets("PlanView_Data_Extract.xlsm").Sheets("Q1 & Q2 2011").Range("A1")
 
Upvote 0
Typed like this:

Range("A1:M65535").Copy Destination:=Worksheets("PlanView_Data_Extract.xlsm").Sheets("Q1 & Q2 2011").Range("A2")

The code gives an error:
"Subscript out of range"
 
Upvote 0
Thanks alot!

That worked great! The problem was that I was trying to access a workbook not worksheet so the code was:

Range("A1:M65535").Copy Destination:=Workbooks("PlanView_Data_Extract.xlsm").Worksheets("Q1 & Q2 2011").Range("A2")

Just for my understanding (i'm new to vba) why did the original code not work?
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

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