How to Record a Macro in Excel (Step-by-Step)

VBA & macros · Updated November 23, 2026

Recording a macro in Excel lets you automate repetitive tasks by capturing your mouse clicks, keystrokes, and formatting actions, then replaying them with a single button or keyboard shortcut. This guide shows you the exact steps to record a macro in Excel for Microsoft 365 on Windows, with notes for Mac and Excel for the web where they differ.

What You’ll Need

  • Excel for Microsoft 365 on Windows (steps are similar for Excel 2016–2024; Mac differences noted).
  • A task you want to automate – for example, formatting a header row or applying a set of number formats.
  • The Developer tab visible in the ribbon. If you don’t see it, right-click any ribbon tab, choose Customize the Ribbon, check Developer in the right pane, and click OK.
  • For Excel on Mac: the Developer tab is enabled via Excel > Preferences > Ribbon & Toolbar.
  • For Excel for the web: macro recording is not supported – you can only run existing macros, not record new ones.

Step-by-Step

  1. Plan your actions. Write down exactly what you want the macro to do. Macros record every click and keystroke, so any mistake (like selecting the wrong cell) will be captured too. Keep the steps simple and linear.
  2. Open the workbook where you want to store the macro. Macros can be saved in the current workbook or in your Personal Macro Workbook (see Tips).
  3. Go to the Developer tab and click Record Macro (in the Code group). On Mac, it’s under Developer > Record Macro.
  4. Name your macro. In the dialog box, enter a name (e.g., FormatHeader). Names must start with a letter, contain no spaces, and cannot conflict with cell references (like “A1”).
  5. Assign a shortcut key (optional). In the Shortcut key field, type a letter (e.g., h). This lets you run the macro with Ctrl+h (Windows) or Cmd+h (Mac). Avoid using existing Excel shortcuts like Ctrl+C or Ctrl+V.
  6. Choose where to store the macro. From the Store macro in dropdown, select:
    • This Workbook – macro is saved inside the current file (only works when this file is open).
    • Personal Macro Workbook – macro is available in all workbooks on your computer (stored in a hidden file called PERSONAL.XLSB).
    • New Workbook – creates a new workbook to hold the macro.
  7. Add a description (optional). Type a short note about what the macro does – helpful for future reference.
  8. Click OK to start recording. Excel now captures everything you do. A small Stop Recording button appears (usually bottom-left of the status bar).
  9. Perform your actions. Use the mouse and keyboard to complete the task you want to automate. For example, select a range, apply bold, set a fill color, or insert a formula. Be careful: any action you take, including scrolling or selecting cells, is recorded.
  10. Stop recording. Click the Stop Recording button on the status bar, or go to Developer > Stop Recording. Your macro is now saved.
  11. Test the macro. Undo your manual changes (Ctrl+Z) or open a fresh sheet, then run the macro via the shortcut key or by going to Developer > Macros, selecting the macro, and clicking Run.

Common Mistakes

  • Not planning ahead. Recording without a clear plan often captures extra clicks that break the macro later.
  • Using absolute cell references when you need relative ones. By default, macros record absolute references (e.g., $A$1). If you want the macro to work on any cell, switch to relative reference mode by clicking Use Relative References on the Developer tab before recording.
  • Forgetting to stop recording. Leaving recording on can accidentally capture unrelated actions.
  • Naming the macro with spaces or invalid characters. This causes an error when you try to run it.
  • Storing the macro in the wrong place. If you save it in “This Workbook” and then open a different file, the macro won’t be available.
  • Assigning a shortcut that conflicts with Excel’s built-in shortcuts. For example, Ctrl+P (Print) would be overridden – not ideal.

Tips

  • Use relative references for flexible macros. Before recording, click Use Relative References on the Developer tab. This makes the macro record actions relative to the active cell, so it works anywhere.
  • Record a macro for formatting only. Macros are great for applying consistent formatting (fonts, colors, borders) across multiple sheets.
  • Keep macros short. If a task is long, break it into several smaller macros. This makes debugging easier.
  • Save your workbook as a macro-enabled file. Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Otherwise, the macro will be lost when you close the file.
  • Use the Personal Macro Workbook for global macros. If you want a macro available in all workbooks, store it there. The first time you do this, Excel may prompt you to enable it – click Enable.
  • Edit the macro in VBA if needed. After recording, you can view the generated VBA code by pressing Alt+F11 (Windows) or Option+F11 (Mac) and tweaking it for more control.

Troubleshooting

  • Macro doesn’t run or shows an error. This often happens if the macro contains a reference to a range that doesn’t exist, or if the workbook is not macro-enabled. Check the file extension: it must be .xlsm. Also, review the VBA code for obvious mistakes (e.g., a typo in a range address).
  • Macro runs but does the wrong thing. You likely recorded extra actions. Re-record the macro, being more careful, or edit the VBA code to remove the unwanted lines.
  • Macro is not available in other workbooks. If you stored it in “This Workbook”, it only exists in that file. Move it to the Personal Macro Workbook by copying the code from the VBA editor (Alt+F11) into the PERSONAL.XLSB module.
  • Security warning about macros. Excel may block macros from untrusted sources. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and choose “Disable VBA macros with notification” (recommended) or “Enable all macros” – but be cautious with files from unknown sources.
  • Shortcut key doesn’t work. The shortcut may conflict with another macro or an Excel built-in. Try a different letter, or run the macro manually via Developer > Macros.
  • Recording is greyed out. This happens in Excel for the web – recording is not supported there. Use the desktop version of Excel.

Frequently Asked Questions

  1. Can I record a macro in Excel for the web? No, the web version does not support recording macros. You can only run existing macros in the desktop app.
  2. Where is the Developer tab? If it’s not visible, right-click any ribbon tab, choose Customize the Ribbon, check Developer in the right pane, and click OK. On Mac, go to Excel > Preferences > Ribbon & Toolbar.
  3. What is the difference between absolute and relative references in macros? Absolute references always point to the same cells (e.g., $A$1), while relative references work relative to the active cell. Use relative references when you want the macro to work on any cell.
  4. How do I delete a macro? Go to Developer > Macros, select the macro, and click Delete. Alternatively, open the VBA editor (Alt+F11), find the module containing the macro, and remove the code.
  5. Can I assign a macro to a button? Yes. Insert a shape or button from Developer > Insert > Button (Form Control), then assign the macro to it in the dialog that appears.
  6. Why does my macro run slowly? Macros that select cells or scroll excessively can be slow. Editing the VBA code to avoid using Select and Activate can speed it up significantly.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.