When you're working with Excel VBA, you might want find the last row with data, so you can paste new data in the row below that.
The following code works up from the last row on the worksheet, until it hits a cell with data. It's like using the End key and Up arrow, to manually move from the bottom of the worksheet.
Sub GetLastRow() Dim ws As Worksheet Dim lRow As Long Set ws = ActiveSheet lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row MsgBox lRow End Sub
In the sample sheet, the last data in column A is in row 10, and that's the result when running the code.
Unexpected Result
This week, I was using similar code in a client's workbook, to find the last row of data. The data was in a named Excel table, and the last couple of rows in the table were blank. I wanted to
Continue reading Last Row Incorrect With Excel Table




Recent Comments