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

VBA & macros · Updated November 23, 2026

Creating a macro in Excel lets you record a series of actions—like formatting, data entry, or calculations—and replay them with a single click. This guide shows you the fastest way to build a macro using the built-in Macro Recorder, which requires no programming knowledge. You’ll also learn how to run, save, and troubleshoot your macro. Before you start, enable the Developer tab if it’s not already visible.

What You’ll Need

  • Microsoft Excel for Microsoft 365, Excel 2021, 2019, or 2016 (Windows or Mac). Steps for Excel for the web are noted where they differ.
  • A workbook you’re comfortable testing on—macros can’t be undone with Ctrl+Z, so save a copy first.
  • Basic familiarity with the actions you want to record (e.g., applying bold, sorting a range).

Step-by-Step

  1. Enable the Developer tab (if not already visible).

    On Windows: go to File > Options > Customize Ribbon. Under Main Tabs, check Developer and click OK.

    On Mac: go to Excel > Preferences > Ribbon & Toolbar, then check Developer under Main Tabs.
  2. Save your workbook as a macro-enabled file before recording. Go to File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm) from the file type dropdown, and save. This prevents losing your macro later.
  3. Open the Macro Recorder. On the Developer tab, click Record Macro. (On Mac, it’s under the same tab.)
  4. Name your macro in the dialog box. Use letters, numbers, and underscores only—no spaces. For example, FormatSales. Add a shortcut key if you want (e.g., Ctrl+Shift+F), but avoid overriding common shortcuts like Ctrl+C.
  5. Choose where to store the macro. Select This Workbook to keep it with the current file, or Personal Macro Workbook to make it available in all your Excel files. (The latter creates a hidden file named PERSONAL.XLSB.)
  6. Add a description (optional) and click OK. The recorder starts immediately; you’ll see Stop Recording on the Developer tab.
  7. Perform the actions you want to record. For example, select a range, apply bold, change fill color, or sort data. Be careful: every click and keystroke is recorded, including mistakes.
  8. Stop recording. Click Stop Recording on the Developer tab (or the square stop button in the status bar).
  9. Run your macro. Press Alt+F8 (Windows) or Option+F8 (Mac) to open the Macro dialog. Select your macro and click Run. Alternatively, use the shortcut key you assigned.
  10. Test on a fresh copy. Always run the macro on a copy of your data first to verify it does exactly what you want.

Common Mistakes

  • Not saving as .xlsm—if you save as .xlsx, Excel strips the macro out, and you’ll lose it.
  • Recording relative vs. absolute references. By default, the recorder uses absolute references (fixed cells). If you want the macro to work on different ranges, click Use Relative References on the Developer tab before recording.
  • Recording unnecessary steps—like scrolling or selecting cells you don’t need. This makes the macro slower and error-prone.
  • Using spaces or special characters in macro names—they cause errors.
  • Forgetting to stop recording—if you switch to another app, the recorder keeps running and records unrelated actions.

Tips

  • Plan your steps before recording. Write down the exact sequence to avoid mistakes.
  • Use relative references when you want the macro to apply to any selected range. For example, to format a selected column, turn on relative references and select the column header.
  • Assign a button on the sheet for easy access: go to Developer > Insert, choose a button (Form Control), and assign the macro.
  • Edit macros in the Visual Basic Editor (VBA) if you need to tweak them. Press Alt+F11 to open it. But remember, the recorder is the safest way for beginners.
  • Keep macros in the Personal Macro Workbook if you use them across many files. It’s hidden, but it’s always available.

Troubleshooting

  • Macro doesn’t run: Check if macros are disabled. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and select Enable all macros (temporarily) or Disable VBA macros with notification. On Mac, go to Excel > Preferences > Security.
  • “Macros are disabled” error: This happens if the file was downloaded from the internet. Right-click the file, select Properties, and check Unblock if present.
  • Macro works but not on other data: Likely because you used absolute references. Re-record with relative references or edit the VBA code to use Selection instead of fixed cells.
  • Macro is too slow: Remove unnecessary steps like selecting cells (e.g., Range("A1").Select). In VBA, you can turn off screen updating with Application.ScreenUpdating = False at the start and True at the end.
  • Can’t find the Developer tab: Make sure you checked it in Options. If it’s still missing, close and reopen Excel.

Frequently Asked Questions

  1. Can I create a macro without the Developer tab? Yes, you can use the status bar: right-click the status bar, check Macro Recording, and a record button appears. But the Developer tab gives you more control.
  2. Will my macro work on Excel for the web? No, the Macro Recorder is not available in Excel for the web. You can run macros in the desktop version only.
  3. Can I undo a macro with Ctrl+Z? No, macros cannot be undone. Always save a copy of your workbook before running a macro.
  4. What’s the difference between a macro and a VBA script? A macro is a recorded set of actions; VBA is the code behind it. You can write VBA manually, but recording is easier for beginners.
  5. How do I delete a macro? Press Alt+F8, select the macro, and click Delete. Or open the VBA editor, find the module, and remove it.
  6. Can I share a macro with someone else? Yes, send them the .xlsm file. They’ll need to enable macros when opening it, and their security settings must allow it.

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.