Skip to main content

How to assign hotkey to specified macro in Excel?

Author Siluvia Last modified

After creating macros, using a hotkey helps you quickly run the code in a workbook. This article is talking about assigning hotkey to specified macro in Excel.

Assign hotkey to specified macro in Excel
Assign hotkey to specified macro with VBA code


Assign hotkey to specified macro in Excel

Please do as follows to assign hotkey to specified macro in Excel.

1. Click Developer > Macros to open the Macro dialog box.

A screenshot showing the Developer tab and the Macros option in Excel

2. In the Macro dialog box, select the macro name you will assign hotkey, and then click the Options button.

A screenshot of the Macro dialog box in Excel where the Options button is highlighted

3. In the Macro Options dialog box, specify a shortcut key in the Shortcut key box, and then click the OK button.

A screenshot of the Macro Options dialog box in Excel where a hotkey is assigned

4. Close the Macro dialog box.

From now on, when using the hotkey (in this case, pressing Ctrl + p keys), the specified macro will run immediately.


Assign hotkey to specified macro with VBA code

You can also apply below VBA code to assign hotkey to specified macro in certain worksheet in Excel.

1. Open the worksheet you want to run specified macro by hotkey, and then right click the sheet name, choose View Code from the context menu. See screenshot:

A screenshot of the context menu in Excel showing the View Code option

2. In the opened Microsoft Visual Basic for Applications window, copy below VBA code into the Code window.

VBA code: Assign hotkey to specified macro

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.OnKey "^{RETURN}", "Clear_ButtonActiveSheet"
End Sub

3. Then press the Alt + Q keys to close the Microsoft Visual Basic for Applications window.

From now on, when pressing Ctrl + Enter keys in the worksheet, the macro named “Clear_ButtonActiveSheet” will run immediately.

Notes:

1. In the code, “^{RETURN}” is the hotkey Ctrl + Enter. And “Clear_ButtonActiveSheet” is the macro name you will run by hotkey. Please change them based on your needs.

2. For assigning hotkey, you can combine any single key with Alt, Ctrl, or Shift, or make any combination of these single keys. Each key is represented by one or more characters. In above case, “^” represents the Ctrl key, “{RETURN} represents the ENTER key. Please use the codes as below table showed.

A table showing VBA key codes for assigning hotkeys in Excel

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!