VBA Excel COUNT Rows

This guide treats “vba excel count rows” the way busy spreadsheet users actually want it: answer first, then the reasoning. It is written for Excel but calls out every place Google Sheets differs, and the platform toggle at the top switches all shortcuts between Windows and Mac so nothing here assumes the keyboard you are not on.

Exact answer

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

VBA macro: Count Rows

Sub Macro1()
    ' count rows — replace the body with your steps
    Dim ws As Worksheet
    Set ws = ActiveSheet
    ' ... your code here ...
End Sub

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

Open Excel and navigate to Developer ▸ Visual Basic (or press Alt + F11).

2

Select Insert ▸ Module from the menu bar inside the VBA editor.

3

Copy and paste Sub Macro1() into the Module.

4

Click anywhere inside the Sub body and press F5 to run.

5

Close the VBA editor and save the file as .xlsm.

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

What this does

Sub Macro1() is a ready-to-run VBA macro that handles count rows 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 Count Rows 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. The difference between a quick fix and a sheet you can trust is the extra minute you spend validating “vba excel count rows”. Start on a copy or a tiny sample, keep the affected rows visible, and compare the result with the tool above before you touch the real workbook. 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. The point is a workflow that saves repeating the same clicks every week, but the practical win is that someone else can open the file and understand what happened without asking you.

A worked example

Example: a colleague sends you a large dataset and asks you to count rows before handing it back. Open the VBA editor with Alt + F11, create a new Module, paste the Sub Macro1() code, and click Run (or press F5). Excel calls the Sub, runs through the sheet, and finishes the Count Rows task automatically. The whole operation takes seconds regardless of how many rows are involved — and because the macro is deterministic, it will produce the same result every time you run it on the same input. Use Sub Macro1() every time you need to count rows reliably at scale. The macro eliminates the most common sources of error in manual work: missed rows, wrong column references, and inconsistent criteria. Once the code is tested and trusted, you can run it repeatedly with one click — zero cognitive overhead, zero variation in output. 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

Everything above works in Google Sheets too. Excel and Sheets share the formula syntax used here; only the surrounding menus are arranged differently. That portability is deliberate — learn it once and it follows you between the two tools and across Windows and Mac. 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. Treat “vba excel count rows” as a small building block rather than a chore. Once the inputs sit in their own cells and the formula reads from them, the same setup answers a dozen related questions with a tweak, and Excel keeps every dependent figure current as the data changes. The tool above is there so you can rehearse and verify before committing anything to a real workbook; the steps and worked example are there so the logic sticks. Get it right once and it stops costing you time — it starts saving it, every time the question comes back around.

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 Macro1() 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 Count Rows macro?

Press Alt + F11 to open the VBA editor, insert a Module (Insert ▸ Module), paste Sub Macro1() into the code pane, and press F5. Alternatively close the editor and run it from Developer ▸ Macros ▸ select "Macro1" ▸ 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 Count Rows macro did?

No — VBA actions generally cannot be undone with Ctrl+Z because they bypass Excel's undo stack. Always test Sub Macro1() 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

People reach this page typing “excel vba rows count” and “rows.count excel vba”, among other phrasings; whichever wording you used, the fix above is the one you want.

Why do people search for this in so many different ways?

Because the same task has many names. “excel vba rows count”, “rows.count excel vba” all point at the one operation explained on this page, which is why they all lead here.