excel vba get last row 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 vba last row
Dim rRange As Range
Dim rDuplicate As Range
Set rRange = ActiveSheet.UsedRange
lFirstRow = rRange.Row
lLastRow = rRange.Rows.Count + rRange.Row - 1
lFirstColumn = rRange.Column
lLastColumn = rRange.Columns.Count + rRange.Column - 1
Set rDuplicate = Range(Cells(lFirstRow, lFirstColumn), _
Cells(lLastRow, lLastColumn))
Example 3: excel vba find last column
With Sheet1
LastCol = .Cells(10, .Columns.Count).End(xlToLeft).Column
End With
LastCol = Sheet1.[XFD10].End(xlToLeft).Column
LastCol = Sheet1.[A10].End(xlToRight).Column
LastCol = LastUsedRow(Sheet1.[A1])
Function LastUsedCol(r As Range)
On Error Resume Next
r.Parent.AutoFilterMode = False
With r.Cells.Find("*", r, xlFormulas, , , xlPrevious)
LastUsedCol = 1
LastUsedCol = .Column
End With
End Function
Example 4: excel vba last row of range
Dim rRange As Range
Dim rDuplicate As Range
Set rRange = ActiveSheet.UsedRange
lFirstRow = rRange.Row
lLastRow = rRange.Rows.Count + rRange.Row - 1
lFirstColumn = rRange.Column
lLastColumn = rRange.Columns.Count + rRange.Column - 1
Set rDuplicate = Range(Cells(lFirstRow, lFirstColumn), _
Cells(lLastRow, lLastColumn))