What a macro does and when you need one
A macro is a recording of steps you repeat in Excel — like formatting cells the same way every time, filling in the same data, or running the same calculations. Instead of doing those steps manually each time, you record them once, then run the macro to do all of them at once. Excel plays back exactly what you recorded, in the same order, every time you run it.
Macros save time when you do the same task more than a few times a week. If you spend five minutes every Monday formatting a report the same way, or ten minutes filling in the same columns with the same formulas, a macro can cut that down to one click. If you only do something once a month, the time to record and test the macro probably isn't worth it.
The simplest way to create a macro is to record your actions as you perform them. Excel watches what you do — what cells you click, what you type, what formatting you apply — and stores those steps. You can then play them back on any spreadsheet, and Excel will repeat every action in the same sequence.
Key Takeaways
- Enable the Developer tab in Excel's ribbon to access the macro recording tools.
- Use the Record Macro button to capture your actions, then perform the steps you want to repeat while Excel watches.
- Stop the recording when you are finished, give the macro a name, and save the file as a macro-enabled workbook (.xlsm).
- Run your macro from the Macros dialog by selecting it and clicking Run, or assign it to a button for one-click access.
- Test your macro on a fresh copy of your spreadsheet to make sure it works the way you expect before using it on real data.
Turn on the Developer tab
The macro tools are hidden by default in Excel. You need to show the Developer tab first. On Windows, click the File menu, then Options. On Mac, click Excel in the menu bar, then Preferences.
In the Options or Preferences window, look for Ribbon & Toolbar (Windows) or Ribbon & Toolbar (Mac). Check the box next to Developer, then click OK. You will now see a Developer tab in the ribbon at the top of your screen, between View and Help (or in a similar location depending on your version).
Record your macro
Open the spreadsheet you want to work with, or create a fresh one to test on. Click the Developer tab, then find the Record Macro button. A dialog box will appear asking you to name your macro and choose where to store it.
Give your macro a short, clear name with no spaces — something like "FormatReport" or "FillWeeklyData". You can add a description if you want to remember what it does later. Leave the storage location set to "This Workbook" unless you have a reason to store it elsewhere. Click OK to start recording.
From this moment, Excel is watching every action you take. Perform the steps you want the macro to repeat — click cells, type data, apply formatting, run formulas, whatever you need. Work slowly and deliberately, because the macro will repeat your actions exactly, including any mistakes. If you click the wrong cell by accident during recording, the macro will click the wrong cell every time you run it.
When you finish the last step, click the Developer tab again and click Stop Recording. The macro is now saved and ready to use.
Save your file as a macro-enabled workbook
Excel files normally save as .xlsx, which cannot store macros. To keep your macro, you must save the file as .xlsm (macro-enabled workbook). Click File, then Save As. In the file type dropdown, select Excel Macro-Enabled Workbook (.xlsm). Choose a location and click Save.
If you forget to save as .xlsm, Excel will warn you when you close the file that macros will be lost. You can go back and save it in the correct format at that point, but it is easier to do it right away.
Run your macro
To run your macro, click the Developer tab and find the Macros button (not Record Macro — the other one). A dialog will open showing all macros in your workbook. Select the macro you want to run and click Run. Excel will perform every action you recorded, in the same order, as fast as it can.
The first time you run a macro, do it on a copy of your spreadsheet or a test file. Watch what happens and make sure the macro does exactly what you intended. If something went wrong during recording, you can delete the macro and record it again.
Assign your macro to a button for faster access
If you run the same macro many times, clicking Developer > Macros > Run every time gets tedious. You can assign your macro to a button on the ribbon or to a shape in your spreadsheet so you can run it with one click.
To add a button to the ribbon, click the Developer tab and select the dropdown arrow next to Insert. Choose Button (Form Control). Draw a button on your spreadsheet by clicking and dragging. A dialog will ask which macro to assign to it. Select your macro and click OK. Now you can click that button to run the macro instantly.
Alternatively, you can right-click any shape or text box in your spreadsheet, select Assign Macro, and choose your macro. This works with any object you draw — a rectangle, circle, or text box — so you can make your macro button look however you want.
Edit or delete a macro
If your macro does not work quite right, you have two choices: record it again from scratch, or edit the code directly. For most users, re-recording is simpler. Delete the old macro by clicking Developer > Macros, selecting it, and clicking Delete. Then record a new version.
If you want to edit the code instead, click Developer > Macros, select your macro, and click Edit. This opens the Visual Basic editor, where you can see the code Excel generated from your recording. This requires some knowledge of Excel's programming language, so it is not the easiest route for beginners. Small fixes are often faster to make by re-recording.
Frequently Asked Questions
What if my macro does something different each time I run it?
This usually means your macro is clicking on cells by their position on the screen rather than by their address. If your data moves or your spreadsheet layout changes, the macro clicks the wrong place. Re-record the macro on a fresh spreadsheet with your actual data layout, and it should work more reliably.
Can I use a macro recorded on one file in a different file?
Yes, but only if both files are saved as .xlsm. You can copy the macro from one file to another by opening both, clicking Developer > Macros, selecting the macro, and clicking Edit. Copy all the code, then paste it into the other file's Visual Basic editor. For most users, it is simpler to record the macro fresh in each file where you need it.
Will my macro work if I share the file with someone else?
Only if they have macros turned on in their Excel settings. By default, Excel disables macros when you open a file from the internet or from someone else for security reasons. When they open your file, they will see a security warning asking whether to enable macros. If they click Enable, the macros will work. If they click Disable, the macros will not run.
What happens if I record a macro and make a mistake partway through?
The macro will record the mistake and repeat it every time you run it. Stop the recording, delete the macro, and record it again. There is no way to edit out a single step in the middle without learning to code, so re-recording is the fastest fix.
Can I record a macro that works on different spreadsheets with different data?
Yes, as long as the data is in the same cells every time. If your data is always in columns A through D and rows 2 through 100, record the macro to work with those cells, and it will work on any file with that layout. If the data location changes from file to file, the macro will not work correctly.