Copy/Paste Issue

Jnrrpg11

New Member
Joined
Jun 29, 2017
Messages
28
Hello folks,

Apologies if this is a obvious issue I'm a beginner at VBA.
I have 2 sheets (Data1 & Data2) with tables of information which will vary in size.
I'm trying to write macro that will find the table size on "Data1" and paste it into a new sheet "AllData"
After that it will find the table size on "Data2" and paste it after the "Data1" info on the sheets "AllData".

Ive played about with this code but continually get a Runtime:1004 at the line in red.


Sub copyandpaste()



Sheets("Data1").Cells.Copy Destination:=Sheets("AllData").Range("A1")


Sheets("Data2").Range("A1", Range("A1").End(xlDown)).Copy
Sheets("AllData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues


End Sub


Any help would be greatly appreciated.

Kind Regards
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
You haven't fully qualified the ranges.
Try
Code:
With Sheets("Data2")
   .Range("A1", .Range("A1").End(xlDown)).Copy
End With
note the . in front of both Range objects.
Also this will only copy col A, rather than the complete data
 

Watch MrExcel Video

Forum statistics

Threads
1,123,307
Messages
5,600,869
Members
414,411
Latest member
Snowmanaus

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
Top