Get the last row

D

dhstein

How can I get the last row in a column in VBA? Not the contents, but the
address. Thanks.
 
M

Mike

Dim LastCell As String
LastCell = Cells(Rows.Count, "A").End(xlUp).Address
MsgBox LastCell
 
J

JLGWhiz

Place both the Sub and the Funciton in standard code module1.
Run Sub lstRw to see how it works. Make sure Sheet1 has data in it.
You can use it for any sheet and you can use Worksheet("shName") or
Worksheet(Index) or Sheets("shName") formats as arguments to return a valid
worksheet object. k will equal the row number.

Sub lstRw()
k = lastRow(Sheets(1))
MsgBox k
End Sub

Function lastRow(sh As Worksheet) 'Finds last cell with
On Error Resume Next 'data in the last used row.
lastRow = sh.Cells.Find(What:="*", After:=sh.Range("A1"), _
LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
 
P

Per Jessen

Hi

Try this:

Dim LastRow as Long
LastRow=Range("A" & Rows.Count).End(xlUp).Row

Regards,
Per
 
Top