In Excel for Microsoft 365 on Windows, assign a macro shortcut by choosing Developer > Macros, selecting the macro, clicking Options, and typing a letter in the Shortcut key box. A lowercase letter creates a Ctrl+letter shortcut; an uppercase letter creates Ctrl+Shift+letter. To open the macro list and run a macro without assigning a shortcut, press Alt+F8.
Assign a keyboard shortcut to a macro
Use these steps for a macro already saved in a workbook:
- Open the workbook containing the macro and select Developer > Macros. If the Developer tab is missing, enable it through File > Options > Customize Ribbon, then check Developer under Main Tabs.
- Select the macro by name in the list. If it is stored in another open workbook or in the Personal Macro Workbook, use the Macros in list to locate it.
- Click Options. In the Shortcut key box, enter one letter. Enter a lowercase letter for
Ctrl+letter, or an uppercase letter forCtrl+Shift+letter. - Optionally add a description, then click OK and close the Macro dialog. Test the shortcut while the workbook containing the macro is open.
For example, entering an uppercase J assigns Ctrl+Shift+J on Windows. That can be easier to remember than a single-letter combination and is less likely to collide with a familiar Excel command. The shortcut is associated with the macro, so you do not need to write VBA just to create the key combination.
Run a macro without assigning a shortcut
A keyboard shortcut is convenient for a macro you use often, but it is not required. On Windows, Alt+F8 opens the Macro dialog, where you can select a macro and click Run. You can also run a selected macro from Developer > Macros. This is useful when you have forgotten a shortcut, want to check the macro’s name, or only run it occasionally.
The Macro dialog lists macros that Excel can run in the currently available workbooks. A macro may not appear if its workbook is closed, if it is not an eligible macro procedure, or if macro security prevents it from being available. A typical runnable VBA macro is a public Sub procedure with no required arguments in a standard module. Choosing the dialog instead of a shortcut does not change what the macro does; it is simply another way to start it.
How macro shortcuts work
Excel’s macro shortcut is a trigger: when you press the assigned key combination, Excel runs the associated macro. It does not record your keystrokes, supply values to the macro, or make a macro available in every copy of Excel. The macro must be stored somewhere Excel can access, and its workbook or macro container generally needs to be open.
When you assign a shortcut to a macro in a workbook, plan to keep that workbook open whenever you need the shortcut. If you want a personal macro to be available across workbooks, you can store it in the Personal Macro Workbook, named PERSONAL.XLSB. Excel opens that workbook in the background when it starts, provided it has been set up and saved. A shortcut for a macro in that personal workbook can then be useful across your Excel sessions on that computer; it does not automatically travel to another computer with an ordinary workbook.
Shortcut assignments can also be easy to forget when sharing a file. Tell colleagues which key combination runs the macro and what the macro changes. The key assignment does not replace the macro itself, and a recipient may need to enable macros or choose a different trusted way to run the code.
Choose a shortcut that will not cause conflicts
Excel allows macro shortcuts to use combinations that may already have a built-in purpose. Assigning a macro to a familiar combination can make Excel’s normal command unavailable while that macro assignment is active. For example, avoid taking over widely used combinations such as Ctrl+C for Copy or Ctrl+S for Save. A shortcut that is hard to remember or that overlaps with a command people rely on can be more disruptive than helpful.
For a macro used regularly, choose a combination that suggests its purpose and is not already part of your routine. On Windows, uppercase letters in the Shortcut key box use Ctrl+Shift+letter, giving you a way to reserve combinations for macros. For example, a team might use Ctrl+Shift+J for a macro that prepares a particular report, provided that combination does not conflict with another add-in or custom shortcut in its setup.
- Prefer a combination you can explain and document clearly.
- Check it against Excel commands and any add-ins or customizations used in your workplace.
- Test it with the relevant workbook open, and confirm that the intended macro runs.
- Tell other users about the shortcut before they rely on the workbook.
Record a macro and give it a shortcut
You can assign a shortcut while recording a macro or later through the Macro dialog. When you start recording, Excel offers a Shortcut key field; the same lowercase-versus-uppercase distinction applies on Windows. Recording is useful for turning a repeatable sequence of Excel actions into a macro, but the recording captures actions rather than understanding the goal behind them. A recorded macro may therefore need editing if it depends on a particular active cell, sheet, or selection.
After recording, stop the recorder and test the result on a safe copy of the workbook. If you assigned a shortcut during recording, record that combination somewhere you can find it. If you did not, use Developer > Macros to select the macro, click Options, and add one afterward. When you choose a shortcut, consider whether the recorded steps will still make sense if the workbook is in a different state when the macro runs.
For a small example, this VBA macro displays a message. Save a copy of the workbook before running a macro; VBA actions cannot be reversed with Ctrl+Z.
Public Sub ShowMacroNotice()
' Display a simple confirmation message.
Dim message As String
message = "The macro ran."
MsgBox message
End Sub
This example has no required arguments, so it can be selected from the Macro dialog and assigned a shortcut. It does not change worksheet data. Real macros can make substantial changes, so inspect their code and test them carefully before using them on important files.
Save the macro in a format that keeps it
A shortcut cannot preserve VBA code if the workbook is saved in a format that removes macros. For a workbook that contains VBA, use Excel Macro-Enabled Workbook (.xlsm) rather than the standard macro-free .xlsx format. When Excel warns that a macro-enabled workbook is being saved in a macro-free format, choosing to continue without macros will discard the VBA project from that saved file.
The shortcut and the code also have a storage location. If you assign it to a macro in one workbook, another workbook does not acquire that macro just because you use the same key combination. If the macro is in PERSONAL.XLSB, the code is stored separately from the workbook you are editing. That can be convenient for personal workflows, but it means the macro will not be included automatically when you send someone a report workbook.
For a shared process, decide whether the macro belongs in the workbook everyone receives or in a managed add-in or other approved location. Explain the required file type and how to run the macro. The best choice depends on whether the code is meant for one file, one user, or a group of users.
Security and safe use
VBA macros can edit cells, delete or move data, and interact with files or other resources. A keyboard shortcut only starts the macro; it does not make its contents safe. Only enable macros in files you trust and understand, and follow your organization’s security policies. If a file came from an unexpected email or download, do not enable its code just to test a shortcut.
Before running unfamiliar or consequential code, review what it does and make a separate copy of the workbook. Excel’s Undo command does not reverse changes made by VBA, so a macro that clears cells or rewrites a range may not be recoverable through Ctrl+Z. A test copy, a backup, or a version-controlled source file provides a safer recovery path. This matters even when the macro is assigned to a familiar key: shortcuts can make it easier to run code accidentally.
Mac and Excel for the web differences
The steps above describe Excel for Microsoft 365 on Windows. Excel for Mac also has a Macros dialog and supports VBA macros, but its menus and keyboard modifiers differ from Windows. In current Mac versions, open Developer > Macros, select the macro, and use Options to set its shortcut; the Mac shortcut convention uses Option+Command+letter. Menu placement and available options can vary somewhat by Excel release. To open the macro list on Mac, use Option+F8; depending on the keyboard and macOS settings, you may need to hold Fn as well.
Excel for the web cannot create, run, or edit VBA macros. A workbook containing VBA can be opened there, but use the desktop Excel app to run or change its VBA code. Office Scripts are a separate automation feature available in supported Microsoft 365 environments; they are not VBA macros and do not use this macro-shortcut assignment method.
Common shortcut problems
If the shortcut appears to do nothing, first check that the workbook containing the macro is open and that macros are permitted for that file. Then open Developer > Macros and try running the macro from the list. If it runs there but not from the key combination, revisit Options to confirm the assigned letter and modifier. Also check whether the active workbook, add-ins, or another customization may be affecting the same shortcut.
If the macro is missing from the list, check the Macros in selection, confirm that the correct workbook is open, and make sure the macro is a runnable procedure rather than a worksheet function or a procedure requiring arguments. If the shortcut runs the wrong command, the combination may conflict with an Excel shortcut or a different macro assignment. Choose another key combination and test it again.
- Shortcut works only in one file: the macro may be stored in that workbook, so keep it open or move the macro to an appropriate shared location.
- Macro disappears after saving: check that the workbook was saved as
.xlsmor another format that supports VBA. - Shortcut does nothing in a browser: open the file in desktop Excel; the web app does not run VBA macros.
- Key combination conflicts: assign a different letter, preferably one that does not replace a common Excel command.
Frequently Asked Questions
What is the Excel shortcut to run a macro?
On Windows, press the shortcut assigned to that macro. If none has been assigned, press Alt+F8 to open the Macro dialog, select the macro, and click Run. On Mac, Option+F8 opens the macro list in supported desktop versions.
Can I use Ctrl+Shift for an Excel macro shortcut?
Yes. In the Windows Macro Options dialog, enter an uppercase letter to assign Ctrl+Shift+letter. This is often preferable to taking over a common Ctrl+letter command.
Do Excel macro shortcuts work in every workbook?
Not automatically. The macro must be available in an open workbook or macro container. A macro stored in a regular workbook is generally available while that workbook is open; a macro in PERSONAL.XLSB can be available across workbooks on the computer where that personal macro file is installed.
Can I run a VBA macro in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in the Excel desktop app to run or edit VBA; Office Scripts are a separate option in supported environments.
Can I undo a macro with Ctrl+Z?
No. Excel’s Undo command does not reverse changes made by VBA. Save a separate copy before running a macro that changes workbook data, especially if you have not reviewed or tested its code.
Related
- How to Hyperlink to Another Cell in Excel
- How to Group Rows in Excel and Hide Them
- Group Rows in Excel: Keyboard Shortcut and Steps
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel Macro Message Box: How to Create and Use OneAn Excel macro message box is a pop-up created with VBA’s MsgBox function. In Excel for Microsoft 365…
- Excel Macros Disabled: How to Enable Them SafelyTo enable a macro in Excel for Microsoft 365 on Windows, open a workbook you trust and select…
- VBA Loop Backwards: Syntax, Examples, and Common ErrorsTo loop backwards in VBA, start at the highest value, end at the lowest, and use a negative…
- VBA Range.Count: How to Count Cells, Rows, and ColumnsIn Excel VBA, Range.Count returns the number of cells in a Range object, including blank cells. For example,…
- Excel VBA AutoFit: Resize Rows and Columns AutomaticallyIn Excel VBA, use the AutoFit method on the rows or columns you want to size. For example,…
- VBA Range Column: How to Reference ColumnsIn VBA, reference a whole worksheet column with Columns("C") or Range("C:C"); to get the column containing a particular…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.