Przedstawiam kilka sposobów jak znaleźć ostatni wiersz.
1. Ostatni wiersz od wybranej komórki:
' Source: n/d Sub test() Dim LastRow As Long ThisWorkbook.Sheets("Sheet1").Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Select LastRow = Selection.Rows.Count End Sub
2. Ostatni wiersz w kolumnie:
' http://www.rondebruin.nl/win/s9/win005.htm Sub OstatniWiersz Dim lastRow As Long With ActiveSheet lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row End With End Sub
3. Ostatni wiersz w zaznaczonym zakresie:
' http://www.ozgrid.com/forum/showthread.php?t=61973 Sub LastRowInrange Dim x As Long, y As Long x = Selection.Rows(1).Row y = Selection.Rows.Count + x - 1 MsgBox x & " " & y End Sub