How to Use Macros in Excel

If you just need to use macros in excel and move on, the boxed answer at the top is all you need. The rest of this page is for when you want to understand why it works in Excel, adapt it to a trickier version, or make it robust enough to hand to a colleague. We keep the opening short on purpose — the depth is here when you want it, not in your way when you don’t.

Exact answer

In Excel: Press Alt + F8, select the macro by name, and click Run — or press F5 with the cursor inside the Sub in the VBA editor. 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: Run a Macro in Excel

Scroll code horizontally to see more
Sub RunMeFromTheMacroDialog()
    Dim ws As Worksheet
    Dim started As Double
    Set ws = ActiveSheet
    started = Timer
    ws.Range("A1").Value = "Ran at " & Format(Now, "yyyy-mm-dd hh:mm:ss")
    MsgBox "Macro completed in " & Format(Timer - started, "0.000") & " seconds.", vbInformation
End Sub

Timer returns seconds since midnight, so subtracting a start value times the run. Stamping the sheet as well as showing a dialog proves the macro really executed rather than merely appearing to.

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 the workbook and click Enable Content if the security bar appears — macros will not run while the file is blocked.

2

Press Alt + F8 to open the Macros dialog.

3

Select the macro by name; the list shows every public Sub across all open workbooks.

4

Click Run, or click Options first to attach a Ctrl + Shift + letter shortcut.

5

To run while editing instead, press Alt + F11, click inside the Sub, and press F5.

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

What this does

There are four practical ways to start a macro, and which one you want depends on who is doing the starting. Alt + F8 opens the Macros dialog listing every public Sub in every open workbook; select and click Run. That is the general-purpose route. F5 inside the editor runs whichever Sub the cursor currently sits in, which is what you use while building and testing. A keyboard shortcut can be attached under Alt + F8 ▸ Options — pick a letter with Ctrl + Shift rather than plain Ctrl, since plain Ctrl + letter combinations overwrite Excel's own shortcuts for that session. Finally, a button or shape with Assign Macro puts it in front of colleagues who will never learn any of the above. There is also automatic execution — event procedures in ThisWorkbook such as Workbook_Open run without anyone asking, which is powerful and worth being deliberate about. Read the code once before running it: note which sheets, ranges and files it touches and whether it deletes or overwrites anything. Macros run only in desktop Excel with macros enabled, and the code is kept only in a macro-enabled format such as .xlsm. Treat “use macros in excel” 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 cells 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

A workbook arrives with a macro called RefreshReport. Click Enable Content on the yellow bar, then press Alt + F8. The dialog lists RefreshReport; select it and click Run. To time it or watch it work, press Alt + F11 instead, click anywhere inside the Sub, and press F5 — that runs the same code but leaves you in the editor where Debug.Print output and any error dialog are visible. Paste Sub RunMeFromTheMacroDialog() into a module and run it both ways: A1 gets a timestamp and the dialog reports the elapsed time, so you can tell at a glance that it ran and how long it took. If the macro does not appear in the Alt + F8 list at all, it is Private, it takes arguments, or it lives in a sheet object rather than a standard module. Knowing all four entry points matters because they fail differently: F5 shows you the error, a button hides it, and a keyboard shortcut can collide with Excel's own. Picking the right one for the audience is most of what makes an automation usable by someone other than its author. If the macro will be shared, add a comment at the top saying what it changes and which sheet it expects, and keep the workbook as .xlsm — saving it as .xlsx removes the code.

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. Treat “use macros in excel” as code you are responsible for: know what it changes, keep a copy of the workbook before running it and keep the file in a macro-enabled format. In Google Sheets and Excel for the web this code does not run; those need a different mechanism.

Common mistakes

  • Running a macro that modifies data without a backup. VBA writes bypass Excel's undo stack, so Ctrl + Z cannot recover anything a macro changed — test on a copy first, every time.
  • Assigning a plain Ctrl + letter shortcut. It silently overrides the built-in shortcut for as long as the workbook is open, so Ctrl + C or Ctrl + S can stop doing what everyone expects. Ctrl + Shift + letter is the safe range.
  • Expecting a macro from workbook A to find data in workbook B. Unqualified references like Range("A1") resolve against whatever is active at the moment the line executes, so which sheet you are looking at when you press Run changes the result.
  • Concluding a macro is missing because Alt + F8 does not list it. Private Subs, Subs that take arguments, and code inside sheet objects are all hidden from that dialog while still being perfectly runnable with F5.

Frequently asked questions

What is the keyboard shortcut to run a macro?

Alt + F8 opens the Macros dialog on the sheet; F5 runs the current Sub inside the VBA editor. You can assign a personal shortcut per macro under Alt + F8 ▸ Options.

How do I stop a macro that is taking too long?

Press Esc, or Ctrl + Break. The editor then offers Continue, End or Debug — Debug stops on the current line so you can see where it was stuck.

Can a macro run automatically when the workbook opens?

Yes. A Private Sub Workbook_Open() in the ThisWorkbook module runs on open, and Worksheet_Change in a sheet module runs whenever a cell there is edited. Both still require macros to be enabled.

Why does nothing happen when I click Run?

Most often macros are still disabled, or the Sub really did run but acted on a different sheet than the one you are looking at. Add a MsgBox as the last line to confirm it reached the end.

Other ways people ask this

On the way here you may have searched this as “how do i use macros in excel”, “using macros in excel”, “how to use macro in excel” and “how to use a macro in excel” — 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. “how do i use macros in excel”, “using macros in excel”, “how to use macro in excel” all point at the one operation explained on this page, which is why they all lead here.