Get the last row

  • Thread starter Thread starter dhstein
  • Start date Start date
D

dhstein

How can I get the last row in a column in VBA? Not the contents, but the
address. Thanks.
 
Dim LastCell As String
LastCell = Cells(Rows.Count, "A").End(xlUp).Address
MsgBox LastCell
 
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
 
Hi

Try this:

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

Regards,
Per
 

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

Back
Top