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
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,819
Messages
5,574,504
Members
412,599
Latest member
Schu94
Top