In Excel: paste Sub FindLastRow() into the VBA editor (Alt + F11 → Insert ▸ Module), press F5 to run, and save as .xlsm to keep the macro. Excel for the web cannot create, run, or edit VBA macros. Open the workbook in the Excel desktop app to work with macros.
On this page8
VBA macro: Find Last Row
Sub FindLastRow()
Dim ws As Worksheet
Dim lastRow As Long
Set ws = ActiveSheet
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
MsgBox "Last row with data in column A: " & lastRow
End SubCells(Rows.Count, 1).End(xlUp).Row is the standard pattern for finding the last used row in column A. Change the column number to target another column.
How to run this macro
- Press Alt + F11 to open the VBA editor.
- Insert > Module.
- Paste the code above.
- Press
F5, or close the editor and run it from Developer > Macros. - Save the file as .xlsm so the macro is kept.
Press Alt + F11 to open the VBA editor.
Insert ▸ Module.
Paste the code above.
Press F5 (or close the editor and run it from Developer ▸ Macros).
Save the file as .xlsm so the macro is kept.
What this does
Sub FindLastRow() is a ready-to-run VBA macro that handles find the last row with data in a column without manual effort. VBA (Visual Basic for Applications) is Excel's built-in automation language: it can read every cell, loop through thousands of rows, and make decisions in milliseconds. To use it, open the VBA editor with Alt + F11, create a Module, paste the code, and press F5. The Find Last Row macro will run immediately — no add-ins, no external tools, just Excel doing exactly what the code tells it to do. A macro runs in the desktop app's VBA environment, not in the cell grid: the workbook has to be saved in a macro-enabled format such as .xlsm to keep the code, and your macro security settings — or a file that arrived from the internet — can block it until you trust it. Excel for the web cannot run VBA at all. Treat “excel last row vba” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected rows shows up while it is still harmless. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That turns a workflow that saves repeating the same clicks every week into a method you can reuse, explain, and defend when the workbook leaves your screen.
A worked example
Practical use: you run the same find the last row with data in a column task every month on a new export. Instead of repeating the steps manually, paste Sub FindLastRow() once into a Personal Macro Workbook (or into the workbook itself), and run it each month via Developer ▸ Macros ▸ Run. The Find Last Row macro applies the same logic to every fresh dataset — consistent, repeatable, and immune to copy-paste slips. Reach for the Find Last Row macro whenever find the last row with data in a column is a task you repeat more than once, involves more than a handful of rows, or needs to be done consistently across multiple workbooks. VBA runs in milliseconds over data that would take minutes by hand, and it never makes the selection mistakes that manual workflows introduce when fatigue sets in. Run a new macro on a copy of the workbook first. Do not count on Undo to reverse what a macro changed; the saved copy is your way back.
In Google Sheets
Google Sheets does not run VBA. A macro written for Excel has to be rewritten in Google Apps Script (Extensions ▸ Apps Script), and an .xlsm file converted to Sheets keeps its cells but drops the code. The aim was to get you unstuck fast and leave you a little more capable than a copy-paste would. The answer is at the top and the detail above shows why it holds — so the next time a colleague asks, you can answer without reaching for search. The short version of “excel last row vba”: paste the code, keep the workbook macro-enabled, trust the file only if you know where it came from, and test on a copy. Code that refers to the active sheet acts on whichever sheet is active, so check that before you run it.
Common mistakes
- Saving as .xlsx instead of .xlsm — Excel strips all VBA code when you save in the non-macro-enabled format. Always choose "Excel Macro-Enabled Workbook (.xlsm)" from the Save As dialog.
- Running the macro on the wrong sheet — Sub FindLastRow() acts on ActiveSheet by default. If you have multiple sheets open, click the correct sheet tab first before pressing Run.
- Macros are disabled — if you see a security warning bar, click Enable Content. If there is no bar at all, set File ▸ Options ▸ Trust Center ▸ Trust Center Settings ▸ Macro Settings to "Disable VBA macros with notification", which is the safe default that still lets you approve a file per workbook. Do not select "Enable all macros": it removes the only warning you get before a hostile workbook executes.
Frequently asked questions
How do I run the Find Last Row macro?
Press Alt + F11 to open the VBA editor, insert a Module (Insert ▸ Module), paste Sub FindLastRow() into the code pane, and press F5. Alternatively close the editor and run it from Developer ▸ Macros ▸ select "FindLastRow" ▸ Run.
Why won't my macro run — macros are disabled?
Excel blocks macros by default for files downloaded from the internet. Click the yellow security bar and choose "Enable Content" — that trusts this one workbook and is all that is normally needed. Leave File ▸ Options ▸ Trust Center ▸ Trust Center Settings ▸ Macro Settings on "Disable VBA macros with notification" rather than switching to "Enable all macros", which Microsoft itself marks not recommended. If the bar is red instead of yellow, the file carries Mark of the Web: close Excel, right-click the file, open Properties and tick Unblock. Also ensure the file is saved as .xlsm, not .xlsx.
Can I undo what the Find Last Row macro did?
No — VBA actions generally cannot be undone with Ctrl+Z because they bypass Excel's undo stack. Always test Sub FindLastRow() on a backup copy of the workbook before running it on live data, or add explicit validation logic inside the macro before the destructive step.
Other ways people ask this
On the way here you may have searched this as “excel vba get last row” and “excel vba last row” — it is all the same task, and this page is the single, complete answer to it.
Why do people search for this in so many different ways?
Because the same task has many names. “excel vba get last row”, “excel vba last row” all point at the one operation explained on this page, which is why they all lead here.