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
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.