To get the last row in Excel using VBA, you can use the “End” property along with the “xlUp” constant. Here’s an example of how you can achieve this:
Sub GetLastRow()
Dim lastRow As Long
' Activate the sheet you want to work with
Sheet1.Activate
' Find the last row in column A
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Print the last row number in the Immediate Window
Debug.Print "Last Row: " & lastRow
End Sub
In the above example, we are activating “Sheet1” to work with, but you can change it to the name of the sheet you want to use. The “Cells” function is used with the “Rows.Count” property to specify that we want to count the number of rows in column A. The “End” property with the “xlUp” constant is used to go to the last non-empty cell in column A. Finally, the “Row” property is used to get the row number of the last cell.