excel get last row in column code example
Example 1: excel vba find get last row in column
With Sheet1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
LastRow = Sheet1.[A1048576].End(xlUp).Row
LastRow = Sheet1.[A1].End(xlDown).Row
LastRow = LastUsedRow(Sheet1.[A1])
Function LastUsedRow(r As Range)
On Error Resume Next
r.Parent.AutoFilterMode = False
With r.Cells.Find("*", r, xlFormulas, , , xlPrevious)
LastUsedRow = 1
LastUsedRow = .Row
End With
End Function
Example 2: excel last used row
Dim rLastCell As Range
Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), _
LookIn:=xlFormulas, LookAt:= xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, MatchCase:=False)
MsgBox ("The last used column is: " & rLastCell.Column)
MsgBox ("The last used row is: " & rLastCell.Row)