Excel VBA Function Key: Run Macros and Assign Shortcuts

VBA & macros · Updated November 21, 2026

In Excel VBA, press F5 in the Visual Basic Editor to run the current procedure; press F8 to step through it one line at a time. To run a macro from an Excel worksheet, use Alt+F8 on Windows to open the Macro dialog, or assign the macro a Ctrl+letter shortcut.

What “Excel VBA function key” can mean

The phrase can refer to a keyboard function key, such as F5, used while working with VBA. It can also mean a keyboard shortcut assigned to a macro, or a VBA function that returns a value. These are related, but they are not the same feature.

The key depends on where you are working. F5 in the worksheet opens Excel’s Go To dialog; F5 in the Visual Basic Editor runs or resumes code. Similarly, F8 in the worksheet extends a selection, while F8 in the editor starts stepping through a procedure. The active application and window matter.

  • Run VBA code: F5 in the Visual Basic Editor.
  • Run a macro from Excel: Alt+F8 on Windows, then select the macro and choose Run.
  • Assign a shortcut: use the Macro dialog’s Options button and choose a Ctrl+letter combination.
  • Use a VBA function: enter its name in a worksheet formula if it is written as a user-defined function.

Run a procedure from the Visual Basic Editor

In Excel for Microsoft 365 on Windows, open the editor with Alt+F11, or choose Developer > Visual Basic. In the editor, place the cursor inside the Sub procedure you want to run and press F5. If execution is paused at a breakpoint, F5 continues from that point instead of starting over.

For example, this simple procedure displays a message when it runs:

Sub ShowNotice()
    Dim messageText As String

    ' Display a short confirmation message.
    messageText = "The macro ran."
    MsgBox messageText, vbInformation, "VBA example"
End Sub

To try it, insert the code in a standard module in the editor, click inside the procedure, and press F5. You can also run a Public Sub without arguments from Excel’s Macro dialog. Before running any macro that changes data, save a copy of the workbook: macro actions generally cannot be undone with Ctrl+Z.

On a laptop, the function keys may control brightness or volume unless Fn Lock is enabled. You may need to press Fn+F5 or Fn+F8, depending on the keyboard and its settings. On Mac, keyboard function-key behavior depends on macOS and the keyboard’s function-key setting; use the Developer tab’s Visual Basic and Macros commands if a shortcut is intercepted.

Useful function keys while debugging VBA

F5 and F8 are the keys many people need first, but other editor shortcuts help diagnose a procedure. Use these while code is open in the Visual Basic Editor:

  • F5: run the current procedure, or continue execution when the code is paused.
  • F8: execute one statement at a time, so you can inspect where a result or error occurs.
  • Shift+F8: step over a procedure call rather than entering the called procedure.
  • F9: set or remove a breakpoint on the current line. A breakpoint pauses execution when that line is reached.
  • Ctrl+Break: interrupt a running procedure on many Windows keyboards. Depending on the keyboard, the Break key may require Fn.

Stepping is useful when code behaves differently from what its author expected. You can inspect variables in the editor as execution pauses, then continue with F8 or F5. A breakpoint is not an error; it is a deliberate pause point. Remove it with F9 or continue running with F5.

Run a macro from the worksheet

To run a saved macro without switching into the editor, press Alt+F8 in Windows Excel. Select a macro from the list and choose Run. If the Developer tab is visible, Developer > Macros opens the same general macro-running workflow. A macro must be available in the open workbook, another open workbook, or a personal macro workbook to appear in the list.

If the Developer tab is missing, enable it through File > Options > Customize Ribbon, select Developer in the Main Tabs list, and choose OK. The tab is a ribbon shortcut to VBA and macro tools; turning it on does not enable macros or change the workbook’s security settings.

On Excel for Mac, use Tools > Macro > Macros or the Developer tab if it is enabled. Keyboard layouts and macOS settings can affect whether a function-key combination works as printed, so the menu command is a useful alternative. Excel for the web does not run VBA macros; open the workbook in the desktop application to use VBA.

Assign a keyboard shortcut to a macro

A macro can be assigned a Ctrl+letter shortcut so you do not have to open the Macro dialog each time. In Windows Excel, open the Macro dialog with Alt+F8, select the macro, and choose Options. Enter a letter in the Shortcut key box and confirm. If you enter a lowercase letter, the shortcut uses Ctrl+letter; an uppercase letter uses Ctrl+Shift+letter.

  1. Save the workbook in a macro-enabled format, such as .xlsm.
  2. Open the Macro dialog and select the intended macro.
  3. Choose Options, enter a letter, and confirm the assignment.
  4. Return to Excel and press the displayed Ctrl shortcut to run the macro.

Choose a combination that does not replace a shortcut you rely on. A macro assigned Ctrl+C, for instance, can interfere with Excel’s normal Copy shortcut while the macro is available. Uppercase assignments, which require Ctrl+Shift+letter, can reduce collisions, though they do not guarantee that every combination is free in every setup. The Options dialog shows the assigned key.

Macro shortcut availability is tied to the macro being available to Excel. A macro stored in a workbook generally requires that workbook to be open. A macro stored in Personal.xlsb can be available across workbooks while that personal macro workbook is loaded. Share the workbook and explain its shortcut if others need to use it; do not assume the shortcut will be obvious to them.

Function keys in Excel versus the VBA Editor

The same physical key can have different effects depending on the active window. This is a common source of confusion when someone says “F5 does not run my macro.” If the worksheet is active, F5 opens Go To. Switch to the Visual Basic Editor and put the cursor in the procedure before pressing F5.

Other Excel uses can also overlap with editor tasks. In a worksheet, F4 repeats the last action in many contexts and toggles cell-reference styles while editing a formula; F9 recalculates formulas; and F11 creates a chart. In the VBA Editor, F9 sets a breakpoint. These differences are normal context-sensitive behavior, not evidence that the key is broken.

The F keys on some laptops are secondary keys. If pressing F5 changes screen brightness, try Fn+F5 or adjust the keyboard’s function-key setting. External keyboards, remote desktop sessions, and utility software can also intercept key combinations. Testing the ribbon or menu command is a quick way to distinguish a shortcut issue from a VBA problem.

VBA functions are different from function keys

A VBA Function is a procedure designed to return a value; a function key is a keyboard key. For example, a user-defined function can be placed in a standard module and called from a worksheet cell. It does not run because you press F5 while the worksheet is active; Excel evaluates it as part of the cell formula.

Public Function AddTax(ByVal amount As Double, ByVal rate As Double) As Double
    ' Return the amount after applying the supplied rate.
    AddTax = amount * (1 + rate)
End Function

After placing this function in a standard module, a cell formula such as =AddTax(100,0.08) returns 108. The example assumes an amount of 100 and a rate of 0.08, or 8 percent. This is only an arithmetic illustration, not tax guidance. A worksheet UDF is intended to return a result; it is not the right mechanism for changing other cells or performing general workbook actions. Use a Sub macro for actions such as formatting a range or copying data.

Macro security and workbook format

VBA macros can change workbook contents, so only run code from a source you trust and understand. A workbook saved as .xlsx cannot store VBA code; save a macro-containing workbook as Excel Macro-Enabled Workbook (*.xlsm) to retain it. Excel may show a security warning when a file containing macros is opened, and organizational policy can restrict macros.

Do not respond to a warning by enabling every macro indiscriminately. If you need to review macro settings on Windows, the path is File > Options > Trust Center > Trust Center Settings > Macro Settings. Follow your organization’s policy, and use the warning and file source to make a deliberate decision. If you only need to inspect code, open the editor without running the procedure.

Common problems and fixes

  • F5 opens Go To: the worksheet is active. Switch to the VBA Editor and place the cursor inside the intended Sub.
  • The key changes brightness or volume: try Fn with the function key, or change the keyboard’s function-key mode.
  • The macro is not listed: check that it is a Public Sub with no required arguments, is in an open workbook, and has not been blocked or disabled.
  • The assigned shortcut does nothing: confirm the workbook containing the macro is open, check the assignment in the Macro dialog’s Options, and ensure macros are permitted.
  • The macro disappeared after saving: the file may have been saved as .xlsx. Save a VBA workbook as .xlsm, then reopen the saved file and check that the code remains.

Not every procedure appears in the Macro dialog. For example, a Function is meant to return a value, and a Sub that requires arguments cannot be launched directly through the ordinary macro list. Code placed in a worksheet or workbook event module may also be designed to run only when its event occurs, rather than as a standalone macro.

Frequently Asked Questions

Which function key runs a VBA macro?
F5 runs or resumes the current procedure in the Visual Basic Editor. In the worksheet, use Alt+F8 on Windows to select and run a macro, or assign it a Ctrl+letter shortcut.

Why does F5 open Go To instead of running VBA?
F5 opens Go To when the worksheet is active. Activate the Visual Basic Editor, click inside the procedure, and press F5. On some laptops, add Fn if the function key is assigned to a hardware control.

What key steps through VBA code?
F8 executes the procedure one statement at a time in the Visual Basic Editor. Use F5 to continue running normally, Shift+F8 to step over a called procedure, and F9 to set or remove a breakpoint.

Can I assign F5 itself to a macro?
The standard Macro Options dialog assigns a Ctrl+letter or Ctrl+Shift+letter shortcut, not an arbitrary F key. Use that dialog’s supported shortcut or run the macro through the Macro dialog, ribbon, or a worksheet control.

Can Excel for the web run VBA?
No. Excel for the web can open and edit many workbook contents, but it does not run VBA macros. Open the file in desktop Excel for Windows or Mac to run VBA, subject to the workbook’s macro settings.

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.