In Excel for Microsoft 365 on Windows, the macro recorder turns many actions you perform in a workbook into Visual Basic for Applications (VBA) code. To use it, choose Developer > Record Macro, carry out the steps you want to automate, then choose Developer > Stop Recording; open Developer > Visual Basic to inspect the generated code. The recorder is useful for repeatable tasks, but it records a sequence of actions rather than understanding your goal, so its output often needs review.
What the Excel macro recorder does
A macro is a saved set of instructions that Excel can run again. When you record one, Excel observes supported commands such as selecting cells, changing number formats, applying fills, entering values, and using certain ribbon features. It translates those actions into VBA statements. You can then replay the macro or edit its code to make it more adaptable.
For example, you might repeatedly format a weekly report: bold the heading row, apply a date format, set column widths, and add borders. The recorder can capture a version of that workflow, giving you both a runnable macro and a starting point for learning VBA. It does not create a plain-language description or a general-purpose automation plan. It records what happened in the workbook and interface at that moment.
The recorder is part of desktop Excel. Excel for the web can open workbooks containing VBA, but it cannot create, edit, or run VBA macros. If you need the recorder, open the file in the desktop application.
How to record a macro
If the Developer tab is not visible in Excel for Microsoft 365 on Windows, enable it through File > Options > Customize Ribbon, then select the Developer checkbox under Main Tabs and choose OK. On a Mac, open Excel > Settings (called Preferences in some versions) > Ribbon & Toolbar and enable Developer. Ribbon labels and available features can vary slightly by platform or build.
- Prepare a copy of the workbook and decide what actions the macro should repeat. Start in a consistent cell or sheet if the workflow depends on a particular starting point.
- Choose Developer > Record Macro. Enter a name beginning with a letter, without spaces; underscores are allowed. You can add a description and, optionally, a shortcut. Avoid assigning a shortcut already used for an important Excel command.
- Choose where to store the macro. This Workbook keeps it with the current file; New Workbook puts it in a separate workbook; Personal Macro Workbook makes it available in Excel on that computer.
- Choose OK, then perform only the actions you want included. Excel records supported operations until you stop it.
- Choose Developer > Stop Recording. To run or inspect the macro, use Developer > Macros or Developer > Visual Basic.
Windows also offers the Developer tab’s Use Relative References control. With relative references off, recorded cell references are generally tied to the same locations; with it on, some recorded movements are relative to the active cell. Choose the mode before recording and test the result from more than one starting cell if you expect to reuse it in different places. Relative recording does not make every action location-independent.
What gets captured in the VBA code
Recorded code commonly includes references to worksheets and ranges, commands that select cells, and statements that change formatting or values. A recorder may produce steps such as selecting a range before setting its font. That can work for the exact layout used during recording, but it may be brittle if rows are inserted, the active sheet changes, or the report grows.
It is also important to distinguish the action from the intention. If you recorded a click on cell B2 and typed a heading, the code may target B2 specifically. It does not infer that you meant “find the first empty cell under the headings.” To express that broader rule, a person generally needs to edit the VBA or write the logic directly.
The recorder is not a complete capture of everything a person can do in Excel. Some interface actions and features are not recorded, and recorded behavior can depend on workbook structure, selection, or platform. It also does not automatically create a button, decide when a macro should run, or add error handling. Treat the output as a useful draft of code, not a guarantee that every part of a complicated process has been automated.
How to view and understand recorded code
Choose Developer > Visual Basic to open the Visual Basic Editor. In its Project Explorer, locate the workbook project and expand Modules; a recorded macro is commonly placed in a module. Double-click the module to see the procedure. If Project Explorer is hidden, use View > Project Explorer in the editor. A macro procedure begins with a Sub line and ends with End Sub.
Look for the procedure name you entered in the Record Macro dialog. The statements between those boundaries describe the recorded operations. Names such as Range, Worksheets, Font, and Interior refer to Excel objects and their properties or methods. A line that begins with an apostrophe is a comment and does not execute.
Recorded procedures often contain Select and Selection statements because the recorder mirrors interaction with the interface. For a small, fixed task, that may be adequate. When editing code, direct references can make the intent clearer, but changing code without understanding the object references can create errors. Make one change at a time, save the workbook, and test on a copy of the data.
A small VBA example and what it illustrates
Here is a short hand-written example of the kind of formatting task a person might record and then simplify. It assumes the workbook contains a sheet named Sales and that its heading occupies A1:D1:
Sub FormatSalesHeader()
' Format the heading row on the Sales worksheet.
Dim headerRange As Range
Set headerRange = ThisWorkbook.Worksheets("Sales").Range("A1:D1")
With headerRange
.Font.Bold = True
.Interior.Color = RGB(217, 225, 242)
End With
End Sub
The declared variable, headerRange, gives a readable name to the range being formatted. The With block applies two formatting settings to that range without selecting it first. This version is still specific to the named sheet and fixed cell addresses; it will not automatically locate a heading if the layout changes. A recorder might produce more intermediate selection statements for similar work, which can be a useful clue about how Excel expresses interface actions in VBA.
Before running any macro, save a separate copy of the workbook. VBA actions cannot be undone with Ctrl+Z, so a mistake may require closing without saving or restoring a backup. On a Mac, the equivalent Undo shortcut is Command+Z, but it likewise does not reverse VBA macro actions.
Saving, running, and sharing macros
A workbook containing VBA must be saved in a macro-capable format, such as Excel Macro-Enabled Workbook (.xlsm) or Excel Binary Workbook (.xlsb). If you save it as the standard .xlsx format, Excel warns that VBA cannot be kept in that format; follow the prompt carefully rather than assuming the macro will remain. A workbook with macros is not automatically trustworthy just because it was created by the recorder.
For a macro stored in the current workbook, select Developer > Macros, choose its name, and select Run. You can also assign a macro to a worksheet button or another supported control, but do this only after checking what the macro does and confirming that the control points to the right procedure. A shortcut can be useful for a frequently repeated task, but it may override a built-in shortcut while the workbook is open.
Personal Macro Workbook is useful for private, reusable procedures. Excel keeps that workbook hidden and opens it when Excel starts, so its macros can be available in other workbooks on the same computer. It is not a convenient way to distribute a macro to colleagues: the code is stored locally, not automatically embedded in each file you send. For sharing, store the macro in the workbook you distribute or use an approved organizational method.
Common problems and practical limits
- The macro works only from one starting cell. The recording may contain fixed references. Record with relative references where suitable, or revise the code and test it from different starting positions.
- It changes the wrong sheet or range. A recorded command may depend on whichever sheet or cell was active. Check the code’s worksheet and range references, and make the intended sheet active before running if the procedure requires it.
- The macro contains many Select statements. This is common in recorder output. It is not necessarily a failure, but selections can make code dependent on interface state and can slow longer procedures. Simplifying them requires care.
- The macro is missing after saving. Check the file extension. A normal .xlsx file cannot store VBA code; use .xlsm or .xlsb when the workbook needs to retain macros.
- Excel blocks the macro. Security settings, file origin, organizational policy, or the workbook’s trust status can prevent macros from running. Do not lower security protections simply to run an unknown file; ask the sender or your administrator to verify it.
Another common misconception is that a macro recorder makes a task safe because it only captures clicks. A recorded macro is executable code. It can change or delete workbook content and may interact with files or other resources if code is later added. Review code from sources you do not trust and keep recoverable copies of important data.
When to use the recorder instead of another tool
Use the recorder when a task is repetitive, consists mainly of supported Excel commands, and works with a reasonably stable workbook layout. It is especially helpful as a learning aid: perform a simple formatting action, inspect the code, and compare the statements with the action. It can also establish a first draft when you know the steps but are not yet comfortable writing VBA from scratch.
For repeatable data cleanup and reshaping, Power Query may be a better fit because it stores transformation steps and can refresh them against updated source data. For automation that needs to react to workbook events, loop through changing ranges, validate input, or make decisions, VBA written or revised with those requirements in mind is usually more suitable than an unedited recording. For cross-platform workflows, consider whether Excel’s available automation tools support the needed features on both Windows and Mac; a Windows-specific control or API may not work on a Mac.
Choosing a tool depends on the job: a short, stable sequence favors recording; recurring imports and transformations favor a refreshable data process; and conditional, branching automation calls for code designed around the rules. A recorded macro can be the beginning of that solution rather than the finished one.
Frequently Asked Questions
Does Excel macro recorder create VBA code?
Yes. In desktop Excel, the recorder translates many supported actions into VBA code and saves the procedure where you specified. It does not capture every possible action or automatically make the procedure flexible.
Where do I find the code for a recorded macro?
Open Developer > Visual Basic, find the workbook project in Project Explorer, and look in its Modules folder. The procedure name is the one entered in the Record Macro dialog. You can also choose Developer > Macros to see available macro names.
Can I record a macro in Excel for the web?
No. Excel for the web can work with a workbook that contains VBA, but VBA macros must be created, edited, and run in desktop Excel. Open the workbook in the desktop app to use the recorder.
Why does my recorded macro fail on another workbook?
It may refer to a particular sheet name, cell address, selection, or workbook structure from the original file. Compare those references with the new workbook and test on a copy. A recording does not automatically adapt when the layout changes.
Can I undo a macro with Ctrl+Z?
No. Excel’s normal Undo history does not reverse actions performed by a VBA macro. Save a backup or a separate copy before running code, especially if it changes or deletes data.
Related
- Microsoft Excel Workbook: What It Is and How to Use One
- Microsoft Excel .xlsx Files: Workbooks and Worksheets
- Import CSV File Into Outlook Contacts: Steps & Tips
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Option Explicit: What It Does and How to Use ItOption Explicit is a VBA module setting that requires you to declare variables before using them. Put it…
- Excel VBA: Loop Through All Open Workbooks in a MacroTo loop through every workbook currently open in desktop Excel, use a For Each loop over Application.Workbooks. Declare…
- Excel VBA: Find a Cell Containing a Specific Date ValueTo find a cell containing a specific date with Excel VBA, loop through the date column and compare…
- VBA Outlook Create Contact Group from ExcelYes. In classic Outlook for Windows, an Excel VBA macro can read email addresses from a worksheet, create…
- Excel VBA Collection vs Dictionary: Which Should You Use?Use a VBA Collection when you need an ordered list of items, optionally addressed by unique string keys;…
- Excel VBA: Get the Number of Sheets in a Workbook EasilyTo get the number of sheets in a workbook with VBA, use the workbook’s Sheets.Count property—for example, ThisWorkbook.Sheets.Count.…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.