Copy and Paste to Bottom Row?

A

andibevan

I am using the following code to select the last row of a data table.

Set last = LastCell(Sheet2)
Cells(last.Row,"A").Select

What line would I need to use to copy the contents of cells from ro
A2:AA2 on Sheet3 (Sheet 3) to the last row?

The "LastCell" statement is a bit of written code used to find the las
row:-

Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%

' Error-handling is here in case there is not any
' data in the worksheet

On Error Resume Next

Any ideas??

Thanks

Andi

With ws

' Find the last real row

LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the last real column

LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

End With

' Finally, initialize a Range object variable for
' the last populated row.

Set LastCell = ws.Cells(LastRow&, LastCol%)

End Function




:) :
 
T

Tom Ogilvy

Sub CopyRow()
Dim rng as Range
set rng = LastCell(worksheets("Sheet2")
Worksheets("Sheet3").Range("A2:AA2").copy _
Destination:=rng.offset(1,0)

End Sub



Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%

With ws

' Find the last real row

LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the last real column

LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

End With

' Finally, initialize a Range object variable for
' the last populated row.

Set LastCell = ws.Cells(LastRow&, LastCol%)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top