VBA - Error when copying a range

Ron512

Board Regular
Joined
Nov 17, 2002
Messages
98
Why I’m I getting, Run time error 1004, application defined or object define error for the below code?

Code:
Worksheets("Sheet1").Range("A5") = Worksheets("Sheet2").Range("A1", Cells(LastRow, 1)).Value

Thanks

Ron
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Two problems..

1, you're not copy/pasting, you're doing A= B..Actually you're doing A = BCDEF
2. When you specify a sheet on the Range object, you must also specify the sheet on the cells properties inside the range..

Try this to actually copy/paste
Rich (BB code):
Worksheets("Sheet2").Range("A1", Worksheets("Sheet2").Cells(LastRow, 1)).Copy Destination:= Worksheets("Sheet1").Range("A5")
If you want only the values, then try
Rich (BB code):
Worksheets("Sheet2").Range("A1", Worksheets("Sheet2").Cells(LastRow, 1)).Copy 
Worksheets("Sheet1").Range("A5").PasteSpecial xlpastevalues
 
Upvote 0
Without seeing the rest of it, my guess is "LastRow" is zero or greater than the allowed number of rows.

Gary
 
Upvote 0
Try something like this...
Code:
Worksheets("Sheet1").Range("A5")[COLOR="Red"].Resize(Lastrow).Value[/COLOR] = Worksheets("Sheet2").Range("A1", [COLOR="Red"]Worksheets("Sheet2").[/COLOR]Cells(Lastrow, 1)).Value
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

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