(file used in the video above)
How to find the last row of data using a Macro/VBA in Excel, including getting the number of that row and any data from that row.
This tutorial shows you the small line of code that will get you the actual row number for the last row of data in Excel and also, if you want, the data from that row.
Range("A" & Rows.Count).End(xlUp).Row
Change the A to whatever column you want to use to find the last row and that's it.
To do something with the row, put it into a variable like this:
last_row is now the variable that will hold the number of the last row of data in column A. You can change the variable name to whatever you want.
Range("A" & Rows.Count).End(xlUp).Select
Change A to the column that you want to use to find the last row of data.
This will select only the cell that is in the column that you specify, column A in this case.
Range("A" & Rows.Count).End(xlUp).EntireRow.Select
Range("A" & Rows.Count).End(xlUp).Value
Change A to the column that will be used to find the last row; this column will also be the column from which the data is gotten.
Now that you have the value, you will probably want to do something with it; so we should put it into a variable so the value is easy to use.
last_row_data is now the variable that will store the data from the cell that is in the last row of the data-set and the column that is specified, A in this case. You can change the variable name to whatever you want.
All of these examples use the same base: Range("A" & Rows.Count).End(xlUp) and the only difference is what is put behind this: row, value, select, or entirerow.select.
The final macro in the included file has all of the above examples so you can clearly see, compare, and become familiar with this code.
Download the attached file to work with these examples in Excel.