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

Hi there,

I am using the following code that I have been told is fairl
infallable at finding the last populated row of my data table. Th
routine Last_Row then displays the last row number. What I can'
manage to figure out how to do is actually select column A of the Las
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 Su

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