Excel Last Row VBA

There are two ways to “excel last row vba”: the quick way you copy and the durable way you understand. This page gives you both. The exact Excel answer is above; below, we build the small mental model that makes the fix stick, so the next variation of the same problem solves itself.

Exact answer

In Excel: paste Sub FindLastRow() into the VBA editor (Alt + F11Insert ▸ Module), press F5 to run, and save as .xlsm to keep the macro.

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 Sub

Cells(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

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
Annotated stepsExcel
1

Press Alt + F11 to open the VBA editor.

2

Insert ▸ Module.

3

Paste the code above.

4

Press F5 (or close the editor and run it from Developer ▸ Macros).

5

Save the file as .xlsm so the macro is kept.

Ctrl+CthenCtrl+Shift+V+Cthen+Ctrl+VPaste values · WindowsMac

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. The same idea underpins a lot of everyday Excel work, so the few minutes spent getting it right here pay back across every sheet you build afterwards. Treat it as a pattern, not a one-off, and it stops being something you look up and starts being something you reach for. 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. A practical tip before you scale it up: build it once on a small block of test data, confirm the number against the tool on this page, and only then point it at your real sheet. That one habit catches almost every mistake while it is still cheap to fix, long before a wrong figure reaches a report or a colleague.

In Google Sheets

If you are in Google Sheets rather than Excel, the good news is that the formula shown here is identical and the workflow barely changes — menus sit across the top instead of in a ribbon, and a few function names differ slightly, but anything you build here moves across with little or no rework. 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, the tool proves it, and the detail above shows why it holds — so the next time a colleague asks, you can answer without reaching for search. Here is the takeaway for “excel last row vba”: copy the answer if you are busy, but if you have a spare few minutes, rebuild the example in Excel yourself with the tool above open beside it. That single pass — type it, run it, watch the result move when you change an input — is what turns a formula you found into a technique you trust. Keep your inputs labelled and referenced, never hard-coded, and the same sheet stays correct and auditable as it grows. Done that way, you will not need to look this up again, and you will be the person others ask.

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.