In this article, you will learn how to find the last row using VBA.
Let us understand with an example:
Following is a snapshot of Sales Report wherein the last row can be identified as 10.
In above example, the number of rows is quite less & we can manually figure out the number of last row; in case there is large number of rows & multiple sheets then, it will be a pain to find the last row & we require VBA code to help us.
Click on Developer tab
From Code group, select Visual Basic
or press ALT + F11 shortcut key to launch VB Editor screen.
Click on Insert, and then on Module
This will create new module.
Enter the following code in the Module
Sub LastRow()
LR = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
MsgBox "The last row is "&LR
End Sub
The result will be shown through Message Box
In this way, you can get the last row of the worksheet using VBA code & now, we can use this code in writing larger codes for automation purpose.
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.