Last Row and Offset

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
I am running into a problems with this code. It is pasteing the copied data into A1 even when the last row a data is in another cell. There are multiple sheets that have seperate macros. This piece of code is in all the macros and is also "DIM" ed in all the macros. Could this be the problem. Any help would be greatly appreciated.



Sheets("Sheet2").Select
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Sheets("Sheet1").Select
LastRow = Range("A" & [a65536].End(xlUp).Row).Offset(1, 0)
ActiveSheet.Paste


I have also tried:

LastRow = Range("A65536").End(xlUp).Row + 1
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You're not specifying *where* to paste the data. If you select Sheet1 and A1 happens to be the selected cell when the code gets to ActiveSheet.Paste, that's where it's going to be pasted.

Edit: Also, you don't have to select the sheets/cells to copy/paste. This works for me:

Code:
Sub test()
Dim CopyRng As Range, PasteRng As Range

Set PasteRng = Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)

With Sheets("Sheet2")
    Set CopyRng = .Range("A1", .Range("A1").SpecialCells(xlLastCell))
End With

CopyRng.Copy Destination:=PasteRng

End Sub
 
Upvote 0
when i put this code in I get an error.


Run-Time Error '438':

Object Doesn't support this property or method
 
Upvote 0
Yeah, sorry about that. What I posted at first was off the top of my head without checking it in VBE. I edited the post to give a (now) working example :)
 
Upvote 0
It works wonderfully....thanks for all your help and patience for the beginner...thanks again
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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