Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


How to assign hotkey to specified macro in Excel?

After creating macros, using hotkey helps you to run the code quickly in 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.

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

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

4. Close the Macro dialog box.

From now on, when using the hotkey (in this case I press the 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:

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.


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 represents 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.

Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.