What macros do and how to turn them on

A macro in Excel is a recorded sequence of actions — clicks, typing, formula entries — that you can play back with a single command. When you record a macro, Excel remembers every step you take: selecting cells, entering data, applying formatting, copying rows. Later, you run that macro and Excel repeats all those steps in the same order, in seconds.

Before you can record or run a macro, you need to enable macros in Excel. By default, Excel disables macros for security reasons. To turn them on, open the file you want to work with, then look for a yellow notification bar below the ribbon that says "Security Warning" or "Macros have been disabled". Click Enable Content on that bar. If you do not see the bar, go to the File menu, select Options, click Trust Center on the left, then click Trust Center Settings, select Macro Settings, and choose Enable all macros (though this is less secure than enabling them per file).

Key Takeaways

  • Recording a macro means clicking the Record Macro button, performing your steps normally, then clicking Stop Recording — Excel captures everything you do.
  • You can run a recorded macro by pressing its keyboard shortcut, clicking a button you assign to it, or selecting it from the Macros dialog and clicking Run.
  • Macros work best for repetitive tasks like formatting the same way every month, copying data between sheets, or filling in standard headers.
  • Macros record absolute cell references by default, so a macro that formats cells A1 through A10 will always format those exact cells, even if you select a different range first.
  • You can edit a macro's code in the Visual Basic Editor, but you do not need to know programming — simple edits like changing cell references are straightforward.

Recording your first macro

To record a macro, go to the View tab on the ribbon and click Macros (the dropdown arrow next to it). Select Record Macro. A dialog box opens asking for a macro name, a keyboard shortcut (optional), and where to store it. The name cannot have spaces — use underscores or camelCase instead, like Format_Monthly_Report or formatMonthlyReport. If you want a keyboard shortcut, type a letter in the Shortcut Key field (Ctrl + that letter will trigger the macro).

Choose where to store the macro: This Workbook means it lives in the file you are working on and moves with it. New Workbook creates a separate file just for macros. Personal Macro Workbook stores it in a hidden Excel file on your computer so you can use the macro in any spreadsheet you open. For most tasks, choose This Workbook. Click OK.

Now Excel is recording. Perform the steps you want to automate: click cells, type data, apply bold formatting, insert rows, whatever you need. Work normally — do not worry about being perfect. When you finish, go back to View > Macros and click Stop Recording. Your macro is now saved.

Running a macro you have recorded

If you assigned a keyboard shortcut when you created the macro, press Ctrl + that letter to run it immediately. If you did not, go to View > Macros and click View Macros (or Macros depending on your Excel version). A dialog opens listing all macros in the current workbook. Click the macro you want and click Run.

The macro executes instantly, repeating every action you recorded. If something goes wrong — the macro formatted the wrong cells or entered data in the wrong place — press Ctrl + Z to undo, just as you would undo any other action.

Assigning a macro to a button on your spreadsheet

Instead of using a keyboard shortcut or hunting through the Macros dialog, you can create a clickable button right on your spreadsheet. Go to the Developer tab on the ribbon. If you do not see it, go to File > Options > Customize Ribbon, check the Developer checkbox, and click OK.

On the Developer tab, click Insert and choose Button (Form Control) — not the ActiveX button. Your cursor changes to a crosshair. Click and drag on your spreadsheet to draw the button. A dialog opens asking which macro to assign. Select your macro and click OK. Right-click the button to edit its label — change it from "Button 1" to something like "Run Report" or "Format Data". Now anyone can click that button to run the macro.

Understanding absolute and relative references in macros

By default, Excel records macros using absolute references. This means if you record a macro that formats cells A1 through A10, that macro will always format those exact cells, no matter which cells you have selected when you run it. This is useful for repetitive tasks on the same cells every time.

If you want a macro to work on whatever cells you have selected before running it, you need to record it using relative references. Before you click Record Macro, go to View > Macros and look for Use Relative References (it may be a button or a toggle). Click it to turn it on, then record your macro. Now the macro will apply to your current selection instead of fixed cells. Turn relative references off again when you finish, so future macros go back to absolute references.

Editing a macro in the Visual Basic Editor

Sometimes you need to change a macro slightly — maybe you recorded it with the wrong cell range, or you want to add a comment explaining what it does. Go to View > Macros > View Macros, select your macro, and click Edit. The Visual Basic Editor opens, showing your macro's code.

You do not need to be a programmer to make simple changes. If your macro references cells A1:A10 and you want to change it to A1:A20, find the text "A1:A10" in the code and change it to "A1:A20". If you want to add a note, type an apostrophe followed by your comment — anything after an apostrophe is ignored when the macro runs. Close the editor when you are done; your changes are saved automatically.

Common tasks that work well as macros

Macros shine when you repeat the same steps regularly. Formatting a monthly report the same way every month — adding borders, shading headers, freezing panes — is a perfect macro task. Copying data from one sheet to another following the same pattern each week works well. Inserting a standard template with your company logo, headers, and column labels is another good use.

Macros are less useful for one-time tasks or for work that changes significantly each time. If you are doing something different every time, recording a macro wastes time. Similarly, if a formula or built-in Excel feature can do the job, use that instead — formulas are faster and easier to edit than macros.

Frequently Asked Questions

Can I undo a macro if it does something wrong?

Yes. Press Ctrl + Z immediately after running the macro, just as you would undo any other action. Excel treats the entire macro as a single undo step, so one Ctrl + Z reverses everything the macro did.

What if I want to delete a macro I no longer need?

Go to View > Macros > View Macros, select the macro, and click Delete. You cannot undo this, so make sure you are deleting the right one. If the macro is stored in your Personal Macro Workbook, deleting it removes it from all your spreadsheets.

Can I share a macro with someone else?

Yes, but they need to enable macros when they open your file, and they should trust that the file is safe. Macros can contain harmful code, so Excel disables them by default. You can also export a macro as a separate file and have someone else import it, but the simplest way is to send them the Excel file with the macro already in it.

Why does my macro not work the same way twice?

This usually happens when your macro uses relative references and you run it on different cell selections. If you recorded a macro to format the current selection, it will format whatever cells you have selected when you run it — which may not be the same cells as last time. Check whether you need absolute or relative references for your task.

Can I record a macro that opens another file or sends an email?

Macros can do these things, but you cannot record them by clicking — you have to edit the code in the Visual Basic Editor. Simple macros work best when you record them by performing the steps normally. For complex tasks involving other programs, you may need to write or edit code, which requires some programming knowledge.