View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JWolf JWolf is offline
external usenet poster
 
Posts: 136
Default Excel VBA - Found last row number but can't select it

Sub test()
Cells(LastCell(Sheet2).Row, 1).Select
End Sub

andibevan < wrote:
Hi there,

I am using the following code that I have been told is fairly
infallable at finding the last populated row of my data table. The
routine Last_Row then displays the last row number. What I can't
manage to figure out how to do is actually select column A of the Last
row - sure it is simple but I am missing it.

Thanks

Andi

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

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

----------------------------------------------

Sub Show_Last_Row()
MsgBox LastCell(Sheet2).Cell

End Sub


---
Message posted from http://www.ExcelForum.com/