In Excel for Microsoft 365 on Windows, go to Developer > Code > Record Macro, give the macro a name, perform the actions you want to automate, and choose Developer > Code > Stop Recording. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if it needs to keep the macro; you can run it later from Developer > Code > Macros or with Alt+F8.
What the Excel macro recorder does
The macro recorder observes many of your actions in Excel and translates them into Visual Basic for Applications (VBA) instructions. When you play the macro, Excel carries out those recorded instructions again. This is useful for predictable, repeatable tasks such as applying the same formatting to a report, setting up a worksheet, or performing a familiar sequence of menu commands.
A recording is not a video of your screen, and it does not understand your goal. It records operations, not intentions. For example, if you select a particular cell and apply bold formatting, the resulting macro may refer to that exact cell. It will not necessarily infer that you meant to bold whichever cell contains a heading in a future report. That distinction explains why a recorded macro can work perfectly on the original sheet but affect the wrong place in a later workbook.
The recorder is a practical starting point for automation, even if you do not know VBA. Excel creates the code in the background, and you can inspect or refine it later in the Visual Basic Editor. For a simple task, you may not need to edit the code at all.
Prepare the workbook before recording
Plan the sequence you want to repeat and use a representative worksheet. Remove accidental selections or unfinished edits first: the recorder may capture the active cell, selected range, and commands you did not mean to include. It is also helpful to decide whether the macro should always target the same cells or work relative to the current selection.
If the Developer tab is missing in Excel for Windows, show it through File > Options > Customize Ribbon. Under Main Tabs, select Developer, then choose OK. In Excel for Mac, use the ribbon and toolbar customization settings to show the Developer tab; wording can differ slightly between Mac releases.
Use a descriptive macro name such as FormatMonthlyReport. Macro names cannot contain spaces, so use underscores or capitalize word beginnings instead. In the Record Macro dialog, you can also add a description and choose where to store the macro:
- This Workbook keeps it with the current file, which is usually best when the macro belongs to that workbook.
- New Workbook stores it in a separate workbook created for the recording.
- Personal Macro Workbook makes it available in Excel on your computer when that hidden workbook loads. It does not automatically travel with a file to another computer.
You can leave the shortcut field blank. If you assign one, choose it carefully: a macro shortcut can take precedence over a normal Excel shortcut while the workbook is open. In the dialog, a capital letter represents using Ctrl+Shift with that letter on Windows.
Record a macro step by step
- Open the workbook and worksheet where you want to record the task. If you need the macro to act relative to the selected cell, turn on Developer > Code > Use Relative References before recording. Otherwise, leave it off for actions aimed at fixed locations.
- Select Developer > Code > Record Macro. Enter a name, optionally set a shortcut and description, and choose where to store the macro.
- Choose OK to begin. Excel is now recording. Carry out only the actions you want repeated, in the order you want them performed. For example, select a range, apply a number format, set a heading style, and adjust column widths.
- When you have finished, choose Developer > Code > Stop Recording. Do this promptly; Excel records eligible actions until recording stops, including extra clicks or formatting you did not intend to automate.
- Save the workbook in a macro-enabled format if the recording is stored in that workbook. To use the macro, open the saved file in the Excel desktop application and run it from the Macros dialog or its assigned shortcut.
On Mac, the Developer tab also provides recording controls. If it is not visible, enable it through ribbon customization. Excel for the web does not create or run VBA macros; open the workbook in the desktop version of Excel to use a recorded VBA macro.
A simple example: formatting a monthly report
Suppose a monthly report always has its title in A1, column headings in row 3, and data in columns A through D. You could start recording with the worksheet in a clean state, select A1, make the title bold and larger, select the heading row and apply a fill color, then adjust the widths of columns A:D. Stop recording as soon as those formatting actions are complete.
If the layout never changes, recording those specific cells and columns may be sufficient. If each month has a different number of data rows, however, a macro recorded while selecting A1:D40 may still target those same rows next time. It will not automatically identify the last row just because the new report contains more or fewer records. You would need to edit the VBA or use a more flexible automation approach for that requirement.
Before relying on the macro, try it on a copy or a fresh sample of the report. Confirm that the correct sheet is active and that the macro changes only the intended cells. A recording can include worksheet selections and navigation steps, so the starting state matters.
Absolute and relative references
The Use Relative References control changes how the recorder describes selections and movements. With relative references off, recorded actions commonly refer to fixed locations. If the recording selects B2 and applies a format, playback can target B2 again. This suits a standard template whose structure does not move.
With relative references on, actions are described in relation to the active cell. For example, you could select a cell at the start of a row, move one cell to the right, and apply formatting there. When the macro runs from a different starting cell, the relative movement can be useful for repeating the action in another location. It does not make the macro intelligent: the starting selection still matters, and it will not find a heading by its text unless the code includes logic to do that.
Choose the mode before recording, and check it before making another recording. A common surprise is a macro that always changes the same cell when the user expected it to work on the current selection, or one that shifts to an unexpected place because the starting cell was different.
Save, inspect, and run the recording
If the macro belongs to the open workbook, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) as the file type. The standard .xlsx format cannot store VBA macros. If Excel warns that saving in a macro-free format will remove the project, do not continue with that format if you need to preserve the macro.
To run a stored macro in Windows, select Developer > Code > Macros, choose its name, and select Run. You can also press Alt+F8 to open the Macros dialog. On Mac, use the Macros command on the Developer tab or the Macros option under the Tools menu; Option+F8 is the corresponding shortcut on many Mac keyboards, though function-key settings may affect it.
To inspect the generated code, choose Developer > Code > Visual Basic. A recorded macro is usually placed in a VBA module. Reading the code can help explain what the macro will select or change, but do not edit code unless you understand the effect. A macro saved in the Personal Macro Workbook is stored separately from the workbook you are working on, so sharing the report file alone will not share that personal macro.
What the recorder can and cannot capture
The recorder works best with straightforward, repeatable commands that Excel exposes as recordable operations. It can capture many cell selections, formatting changes, entries, formulas, and ribbon or menu commands. Some recorded actions may depend on the current worksheet, selection, workbook structure, or version of Excel.
It does not automatically create decision-making rules. If the task is “format every row where status is overdue,” the recorder cannot infer that condition from a one-time sequence of clicks. Nor does a recording reliably turn a fixed example into a reusable tool that handles changing layouts, missing data, or unexpected errors. Those requirements usually call for VBA editing, formulas, or a different automation feature.
Also, not every action in Excel is recordable, and the recorder may produce code that is more literal than a person would write. A macro that selects cells repeatedly can be less adaptable than code that works directly with ranges. Treat the recording as a starting point, then test it with realistic variations in the data and layout.
Common recording and playback problems
- The macro is missing after reopening the file: Check that it was stored in the workbook and that the file was saved as
.xlsm. A macro in the Personal Macro Workbook is not embedded in the report file. - The macro runs on the wrong cells: Check the active sheet, starting selection, and whether relative references were on when you recorded. Re-record or revise the macro for the layout you actually need.
- The Macros dialog is empty: Confirm that the correct workbook is open and that the macro was not stored in another workbook or the Personal Macro Workbook. Excel for the web cannot run VBA macros.
- A security warning appears: Excel may block macros from an untrusted file or location. Do not enable them just to make a warning disappear; verify the source and follow your organization’s security rules.
- You want to undo a run: Excel macros generally cannot be reversed with Ctrl+Z. Close without saving if appropriate, or restore a backup. Make a copy before testing a macro that changes important data.
Macro safety and sharing
A VBA macro can change or delete workbook content and may perform other actions allowed by its code. Only enable macros in files from a source you trust. If a colleague sends a macro-enabled workbook, ask what the macro does or have the code reviewed rather than assuming that a familiar filename makes it safe. For work devices, follow the rules set by your organization’s administrator.
Before running a new or edited macro, save a separate copy of the workbook. This is especially important because macro actions cannot normally be undone through Excel’s undo history. When sharing a workbook, explain that it contains a macro and tell recipients which desktop Excel features it needs. Recipients may have different security settings, and the macro will not run in Excel for the web.
When another tool may fit better
Use the macro recorder when the task is a repeated sequence of Excel commands and the workbook structure is reasonably consistent. If you need branching rules, loops, custom prompts, or robust handling of changing ranges, a VBA macro that is reviewed and adapted may be more appropriate than a raw recording.
For repeatable data importing and cleanup, Power Query can be a better fit because it saves transformation steps and refreshes them against new data. For browser-based workflows, Office Scripts may be available in Excel for the web through the Automate tab, depending on the account and organization settings. These tools are not interchangeable with VBA: choose based on where the workbook will run and the kind of task you need to automate.
Frequently Asked Questions
Can I record a macro without knowing VBA?
Yes. Start and stop the recorder through the Developer tab, and Excel writes the VBA instructions for you. Basic recordings can be run without editing code, although understanding the generated actions helps when troubleshooting or adapting them.
Why did my recorded macro change the wrong cells?
The recording may contain fixed cell addresses, or it may rely on a particular starting selection and active worksheet. Check whether Use Relative References was on, then test the macro from the same starting point it expects.
Can I record a macro in Excel for the web?
Excel for the web does not record or run VBA macros. Use Excel for Windows or Mac to work with VBA macros; Office Scripts may be an alternative for supported browser-based automation.
Will a macro work if I save the file as .xlsx?
No. The .xlsx format does not preserve VBA macros. Save a workbook containing its macro as .xlsm, or store the macro in the Personal Macro Workbook if it is meant for your own Excel installation.
Can I undo a macro with Ctrl+Z?
Usually not. Running a macro clears Excel’s normal undo history, so save a backup copy before running it on important data. If the result is wrong, restore the copy or close without saving when that is safe for your work.
Related
- Merge Cells but Keep All Text in Excel: Safe Methods
- Microsoft Excel Always Not Responding? Causes and Fixes
- Merge Cells but Keep All Data in Excel: What Works
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Google Sheets Macros: How to Create, Run, and Edit ThemYes. You can create macros in Google Sheets using its built-in recorder: in a desktop web browser, choose…
- Excel VBA Range Syntax: Examples and Best PracticesIn Excel VBA, a range is a cell or group of cells, usually referenced with Range("A1") or Range("A1:C5").…
- Excel VBA Data Validation List: Setup and ExamplesIn Excel for Microsoft 365 on Windows, create a VBA dropdown by applying data validation with Type:=xlValidateList and…
- Zoho Sheet VBA: How to Delete the Selected Row in ExcelZoho Sheet does not run Excel VBA macros, so there is no VBA command you can paste into…
- VBA MsgBox New Line: Add Line Breaks to MessagesTo add a new line in a VBA MsgBox, join the message text with vbCrLf or vbNewLine where…
- How to Add Macros to Google Sheets and Automate TasksTo add a macro in Google Sheets, open the spreadsheet in a desktop web browser, choose Extensions >…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.