An Excel macro is a recorded set of clicks and keystrokes that Excel can replay for you, and a beginner can create one in about two minutes without writing any code. The trick is to record it in the right place, store it in the right file type, and give it a way to run later — those three choices cause most of the trouble beginners hit. To get started, open Excel, make sure the Developer tab is visible, record a short task, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm).
Menus and labels can differ slightly by Excel version, platform and region, so if a button is not where described, look for a close equivalent. The steps below are written for Excel on Windows; the Mac differences are noted where they matter.
What You'll Need
- A desktop copy of Excel on Windows or Mac. Macros are not available in Excel for the web, and recording is not supported in the mobile apps.
- A spreadsheet with a repetitive task worth automating — formatting a table, cleaning text, adding a summary row, and so on.
- The Developer tab turned on, or the ability to turn it on (it takes a few clicks and is explained below).
- An understanding that macro-enabled files must be saved as
.xlsm, not the usual.xlsx.
Step-by-Step
Save your workbook first. Press
Ctrl+Sand save the file as an Excel Macro-Enabled Workbook. If you record a macro into a normal.xlsxfile, Excel will strip the macro the next time you save, and you will lose the work with no warning beyond a dialog.Turn on the Developer tab. Go to File > Options > Customize Ribbon, tick Developer in the right-hand list, and click OK. On Mac, use Excel > Preferences > Ribbon & Toolbar and tick Developer. The tab now appears next to View.
Decide exactly what the macro should do. Write down the sequence in plain language: “select A1:F1, bold it, fill it light grey, add a bottom border.” Recording everything you improvise produces fragile macros, because every accidental click is recorded too.
Choose where to store the macro. Click Developer > Record Macro. In the dialog, give it a clear name with no spaces (for example
FormatHeader) and pick This Workbook under “Store macro in” so it stays with the file. Choosing Personal Macro Workbook makes it available in every workbook you open on that computer.Optionally assign a shortcut. In the same dialog you can set a keyboard shortcut by typing a letter in the shortcut box. Excel will use
Ctrlplus that letter, so avoid letters already used by built-in shortcuts. You can also skip this and run the macro from the macro list.Click OK and perform the task slowly and deliberately. The recorder is now running — a small stop button appears in the status bar. Do exactly the steps you planned, using the keyboard where you can rather than the mouse, because keyboard navigation records more reliably than clicking on cells at specific screen positions.
Stop recording. Click Developer > Stop Recording, or click the stop square in the status bar. Nothing else should be done in the workbook before you stop.
Test it. Click Developer > Macros, select your macro and click Run. Watch what happens and compare it with what you intended. If it does the wrong thing, press
Ctrl+Zto undo — macros can usually be undone, though not always — then re-record rather than trying to patch a broken recording.Save and reopen to confirm. Save the
.xlsmfile, close it and open it again. Excel shows a yellow security bar saying macros have been disabled. Click Enable Content only if you created the file or trust its source. If your macro has vanished from the list, the file was probably saved as.xlsx.
Common Mistakes
Saving in the wrong format. This is the single most common beginner problem. Recording into an .xlsx file works until you save, at which point the macro is discarded. Always save as Excel Macro-Enabled Workbook.
Recording with the wrong cell selected. If you start recording with cell D7 active and the macro later runs from A1, the actions apply relative to wherever you happen to be. Before recording, select A1 (or the exact starting cell), or use the Use Relative References button on the Developer tab so the macro works from the current cell instead.
Recording extra clicks. Scrolling, clicking a sheet tab, or selecting a cell to check something all get recorded. Keep the recording short and clean.
Naming a macro like a cell reference. Names cannot contain spaces, cannot start with a number, and cannot look like a cell address such as A1 or R1C1.
Running a macro on the wrong sheet. A recorded macro acts on whatever sheet is active. If your macro formats column headers, it will happily format column headers on the wrong sheet if that is the one open. Check the active sheet first.
Tips
Record one small task per macro rather than one giant macro for everything. Small macros are easier to test, and if one step breaks you only re-record that part.
Use the Macros dialog to name a macro Auto_Open if you want it to run automatically when the workbook opens — but be aware it can trigger security prompts and confuse other users, so mention it in the file.
Keep a backup copy of the workbook before testing anything that deletes rows or clears data. Undo does not always reverse a macro, especially one that deletes sheets or writes over large ranges.
If you want to see what the recorder actually wrote, press Alt+F11 to open the Visual Basic editor and look at the module under your workbook. You do not need to understand it to use macros, but reading a few recorded lines is the fastest way to learn the vocabulary.
Share macro-enabled files only with people who expect them. Many email systems block .xlsm attachments outright, so a shared drive or a link is usually more reliable.
Troubleshooting
The Developer tab is missing. It is turned off by default. Follow step 2 above to enable it, or use the older shortcut Alt+F8 to open the macro list, which still lets you run and record macros.
The macro is not in the list. Check the “Macros in” dropdown at the bottom of the Macros dialog — it may be set to This Workbook while the macro is stored in the Personal Macro Workbook. Also confirm the file is saved as .xlsm.
Excel shows a security warning every time. This is normal for macro-enabled files. If the file sits in a trusted location, such as a folder you or your IT team have marked as trusted, the prompt can be skipped. If you did not create the file and do not know where it came from, do not enable the macros.
The macro does the right thing sometimes and the wrong thing other times. This almost always means relative versus absolute references. Re-record from a fixed starting cell, or deliberately use Use Relative References if you want the macro to work from wherever the cursor is.
Excel freezes or shows a “code execution has been interrupted” message. Press Esc to stop, then Ctrl+Break if it persists. Close the workbook without saving if data looks corrupted, reopen, and re-record a shorter macro.
The file will not open on a Mac or in Excel for the web. Mac Excel can run macros but not all of them, and Excel for the web cannot run macros at all — it will open the file but the macros will not work. Use a desktop version.
Frequently Asked Questions
Do I need to know how to code?
No. The recorder writes the code for you. Reading and editing that code is optional and comes later if you want it.
Can a macro be undone?
Sometimes. Simple formatting and data changes can usually be reversed with Ctrl+Z, but macros that delete sheets or close files often cannot. Save a copy first.
Why does the macro disappear when I save?
Because the workbook is saved as .xlsx. Save as Excel Macro-Enabled Workbook to keep it.
Do macros work in Excel for the web or on phones?
No. Running and recording macros requires the desktop version of Excel on Windows or Mac.
Is it safe to enable macros in a file someone sent me?
Only if you trust the sender and the source. Macros can do anything you can do in Excel, including deleting files, so treat an unexpected macro-enabled file with caution.
Can I share a macro with a colleague?
Yes — send the .xlsm file itself. The macro travels with it, but your colleague will need to click Enable Content when they open it.