
An Excel macro records a repetitive task so you can run it again with a button, menu command, or keyboard shortcut. Excel writes the VBA code behind the scenes while you perform the steps normally.
Does this affect you?
Use this for Excel for Microsoft 365, Excel 2021, and Excel 2019 on Windows or Mac when the same formatting, sorting, entry, cleanup, or report-prep task keeps repeating.
Record your first macro
Turn on the recorder, do the task once, then stop recording.
- If the Developer tab is hidden, enable it from File > Options > Customize Ribbon on Windows, or Excel > Preferences > Ribbon & Toolbar on Mac.
- Open Developer > Record Macro.
- Give the macro a short name with no spaces, such as FormatReport.
- Optionally assign a shortcut key.
- Choose where to store it, then click OK.
- Perform the task exactly as you want Excel to repeat it.
- Open Developer again and click Stop Recording.
- Run it later from Developer > Macros, or with the shortcut if you assigned one.
The recorder captures the specific clicks, selections, and keystrokes you make, so plan the task before you start recording.
Make a macro available in every workbook
Store common personal macros in the Personal Macro Workbook.
- When recording, set Store macro in to Personal Macro Workbook.
- Excel creates PERSONAL.XLSB the first time you use it.
- The macro becomes available from Developer > Macros in any workbook on that computer.
- If Excel asks to save changes to the Personal Macro Workbook when closing, choose Save.
Personal macros are stored on that installation of Excel. They do not automatically follow your Microsoft account to another computer.
More control
Use the right file type
A normal .xlsx workbook cannot store macros. If the macro belongs inside the workbook, save it as an Excel Macro-Enabled Workbook (.xlsm).
Handle security warnings
Excel disables macros from untrusted files by default. Click Enable Content only when you trust the file and its source, because macros can run code.
Edit the recorded code
Open Developer > Macros, select the macro, and click Edit. The Visual Basic Editor shows the recorded VBA, where small changes such as a cell reference or color value may be easy to adjust.
Add a worksheet button
Use Developer > Insert > Button under Form Controls, draw it on the sheet, and assign the macro. Users can then run the macro with one click after enabling macros.
Sources
- Microsoft Support – Automate tasks with the Macro Recorder (2025)
- Microsoft Support – Run a macro (2025)
- Microsoft Support – Enable or disable macros in Office files (2025)
