How can I determine the last row in an Excel sheet, including some blank lines in the middle?
With this function:
Function ultimaFilaBlanco(col As String) As Long Dim lastRow As Long With ActiveSheet lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, col).End(xlUp).row End With ultimaFilaBlanco = lastRow End Function
And this data:
Row 1 : Value Row 2 : Value Row 3 : Value Row 4 : Value Row 5 : Value Row 6 : White Row 7 : Value Row 8 : Value Row 9 : Value Row 10 : White Row 11 : White Row 12 : White Row 13 : Value Row 14 : White
The function returns 5, and I need 13. Any idea how to do it?
Example #2 – Using Range and SpecialCellsStep 1: Define a variable again as Long. Step 2: Start storing the value to the variable Last_Row using the assignment operator. Step 3: Start Typing Range(“A:A”). Step 4: Use the SpecialCells function to find out the last non-empty cell.
Locate the last cell that contains data or formatting on a worksheet. To locate the last cell that contains data or formatting, click anywhere in the worksheet, and then press CTRL+END.
The VBA snippet End(xlup). Row will find the last used row in an Excel range. Knowing the last row in Excel is useful for looping through columns of data.
The best way to get number of last row used is:
ActiveSheet.UsedRange.Rows.Count
for the current sheet.
Worksheets("Sheet name").UsedRange.Rows.Count
for a specific sheet.
To get number of the last column used:
ActiveSheet.UsedRange.Columns.Count
for the current sheet.
Worksheets("Sheet name").UsedRange.Columns.Count
for a specific sheet.
I hope this helps.
Abdo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With