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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
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
 

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
when i put this code in I get an error.


Run-Time Error '438':

Object Doesn't support this property or method
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
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 :)
 

bschulze

Active Member
Joined
Jun 2, 2005
Messages
289
It works wonderfully....thanks for all your help and patience for the beginner...thanks again
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,447
Messages
5,831,691
Members
430,082
Latest member
mrmedeiros

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