Excel VBA: How to Assign a Keyboard Shortcut to a Macro

VBA & macros · Updated November 19, 2026

To assign a keyboard shortcut in Excel for Microsoft 365 on Windows, press Alt+F8, select the macro, choose Options, enter a letter in the Shortcut key box, and select OK. A lowercase letter assigns Ctrl+letter; an uppercase letter assigns Ctrl+Shift+letter.

Assign a shortcut from the Macros dialog

The shortcut is set in Excel’s macro list, not in the VBA editor. First make sure the macro is available in the workbook you want to use. Then follow these steps:

  1. Press Alt+F8 to open the Macro dialog. Alternatively, select Developer > Code > Macros. If the Developer tab is not visible, turn it on through File > Options > Customize Ribbon and select the Developer checkbox.
  2. Select the macro in the list. If several workbooks are open, check the Macros in list or the macro name so you choose the intended one.
  3. Select Options. In the Shortcut key box, type one letter. Do not type Ctrl or Shift; Excel supplies those keys.
  4. Select OK, then close the Macro dialog. Press the shortcut in a worksheet to run the macro.

For example, entering lowercase r assigns Ctrl+R. Entering uppercase R assigns Ctrl+Shift+R. Excel does not provide a general shortcut editor here for combinations such as Ctrl+Alt+R, function keys, or a multi-key sequence; the Macro Options dialog uses a letter with Ctrl, optionally combined with Shift.

What the macro shortcut does

A macro shortcut is a direct way to start a VBA procedure while working in Excel. It does not change the macro’s code or make the macro run automatically when the workbook opens. You press the assigned key combination when you want to run it.

The shortcut is associated with the macro in the workbook, rather than being a universal Excel setting for every file. To use a workbook-specific shortcut, the workbook containing the macro needs to be open. If you close that workbook, its macro is no longer available through Excel. A shortcut stored with a workbook is useful for a personal tool or a team workbook, but it is not the same as installing a system-wide keyboard command.

Excel can also assign the same key combination in more than one place. That can make it unclear which command will respond when multiple workbooks are open, especially if each contains a macro using the same shortcut. Avoid duplicate assignments where possible, and test the shortcut with the intended workbooks open.

Make sure the macro is eligible

For a straightforward assignment, use a public, parameterless Sub procedure in a standard VBA module. A procedure that requires arguments cannot be run directly from the Macro dialog because Excel has no prompt for supplying those arguments. Procedures declared Private, event procedures such as Worksheet_Change, and code placed in a worksheet or ThisWorkbook object are not the usual choices for a directly assigned macro.

To inspect or add a standard module, press Alt+F11 to open the Visual Basic Editor. In the Project Explorer, select the project for the correct workbook, then choose Insert > Module. Put a normal macro procedure in that module. The Developer tab’s Visual Basic command also opens the editor. If the Project Explorer is hidden, use View > Project Explorer in the editor.

A recorded macro is often suitable, but recording can produce code that depends on the current selection, active sheet, or exact worksheet layout. Before assigning a shortcut, run the macro manually from Alt+F8 and confirm that it does what you intend. A shortcut makes a procedure easier to launch; it does not make fragile code safer or more reliable.

Example: a simple macro to assign

This example displays the current date. It has no arguments and can be placed in a standard module, so it can be selected in the Macro dialog. The declared variable holds the date used in the message.

Public Sub ShowReportDate()
    ' Display today's date in a readable format.
    Dim reportDate As Date
    reportDate = Date
    MsgBox "Report date: " & Format$(reportDate, "mmmm d, yyyy")
End Sub

After adding the code, return to Excel, press Alt+F8, select ShowReportDate, and choose Options to assign a letter. Save a copy of the workbook before running any macro that changes data: VBA actions generally cannot be reversed with Ctrl+Z. This example only displays a message, but the same precaution matters for procedures that edit cells, delete rows, or overwrite files.

Choose a shortcut that will not cause trouble

Many familiar Ctrl combinations already have jobs in Excel or Windows. Assigning a macro to one of them can override the normal command while the macro’s workbook is available. For instance, Ctrl+R is commonly used in Excel to fill cells to the right, so using lowercase r for a macro could interfere with that workflow. The exact effect can depend on the active workbook and Excel context.

Before choosing a letter, consider where the workbook will be used and what the shortcut means to its users. A practical approach is to:

  • Prefer a combination that is not part of your everyday Excel work.
  • Use Ctrl+Shift+letter if the unshifted Ctrl combination is important to you.
  • Write the shortcut in a worksheet instruction or a short user guide, especially for shared workbooks.
  • Test it with the workbook open and then close the workbook to check that normal Excel behavior returns.

Ctrl+Shift does not guarantee a conflict-free choice: applications, add-ins, keyboard layouts, and Excel features may use combinations too. If a shortcut behaves unexpectedly, choose another letter rather than assuming the macro code itself is at fault.

Save the file and consider macro security

A workbook containing VBA needs a macro-enabled format. Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm), or another suitable macro-capable format such as Excel Binary Workbook (*.xlsb). A standard .xlsx file cannot store VBA code. If you save a macro-enabled workbook as .xlsx, Excel warns that the VBA project will be removed if you continue in that format.

Saving the workbook is important after assigning the shortcut as well as after editing the code. If the shortcut or code has not been saved, closing Excel can discard the change. When sharing the file, tell recipients that it contains macros and explain what the assigned shortcut runs. Recipients may need to allow macros according to their organization’s security policy. They should only enable macros in files from sources they trust; a keyboard shortcut is not a security check and does not make unknown VBA safe.

If you want a macro available across workbooks on your own computer, Excel’s Personal Macro Workbook, PERSONAL.XLSB, is one option. It loads when Excel starts and is normally hidden. A macro stored there can be available across sessions, but it is local to that Excel installation unless you deliberately distribute the file or use another deployment method. For a shared workflow, an add-in or a clearly documented macro-enabled workbook may be easier to manage.

Common problems and how to fix them

  • The macro is missing from the list: Check that the intended workbook is open, that the code is in a standard module, and that the procedure is a public Sub with no required arguments. Also check the Macros in selection in the dialog.
  • The shortcut does nothing: Confirm the workbook is open, the macro is enabled under your organization’s rules, and the key combination matches the lowercase or uppercase letter you entered. Try selecting the macro in Alt+F8 and running it directly to separate a shortcut issue from a code issue.
  • The normal Excel command stops working: The macro may be using a shortcut that conflicts with a built-in command. Reassign it to a less disruptive letter in Macro Options.
  • The macro works only in one file: That is expected for a macro saved in that workbook. Move or copy the macro to PERSONAL.XLSB or package it as an add-in if you need broader availability.
  • The assignment disappears: Save the file in a macro-capable format and save after changing the assignment. A .xlsx copy cannot preserve the VBA project.

Mac and other ways to launch a macro

Excel for Mac also provides a Macros dialog and an Options control for assigning a letter shortcut. In Excel for Mac, open Tools > Macro > Macros from the menu bar, select the macro, and choose Options. The exact key behavior and available combinations can differ because macOS and Mac keyboards use their own system shortcuts; follow the combination shown by the dialog and check for conflicts on that Mac. Windows’ Alt+F8 instruction is not the Mac menu path.

Excel for the web does not run VBA macros, so a VBA shortcut cannot be used there. A workbook with VBA can be stored online and opened in desktop Excel, but the macro needs the desktop application to execute. If the task must work in a browser, consider whether an Office Script or another web-compatible workflow fits instead; Office Scripts are distinct from VBA and are not simply the same macro with a different shortcut.

Other launch options can be more discoverable than a keyboard command. The Developer tab’s Macros button opens the macro list, and a Form Control button on a worksheet can run a macro when clicked. A Quick Access Toolbar command or a custom Ribbon control can also suit a frequently used tool, though setup differs from assigning a letter in Macro Options. Choose the launch method based on who needs to find the action, not only on how quickly you can press it.

Frequently Asked Questions

Can I assign a macro to Ctrl+Shift+letter?
Yes. In the Macro Options dialog, enter an uppercase letter to use Ctrl+Shift+that letter. Entering a lowercase letter uses Ctrl+that letter.

Can I assign a macro to a function key or Ctrl+Alt shortcut?
Not through the standard Macro Options shortcut box, which accepts a letter and uses Ctrl, optionally with Shift. A button, Ribbon control, or add-in may be a better launch method if you need a different key combination.

Does the shortcut work when the workbook is closed?
No, not when the macro exists only in that workbook. Keep the workbook open, or place the macro in a loaded Personal Macro Workbook or add-in if you need it available elsewhere.

Can I change or remove the shortcut later?
Yes. Open Alt+F8, select the macro, choose Options, and change or clear the letter in the Shortcut key box. Save the workbook afterward.

Can I assign the shortcut in Excel for the web?
No. Excel for the web does not execute VBA. Open the macro-enabled workbook in desktop Excel to run its VBA macro.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.