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.
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 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.
Best Office Productivity Tools
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!
