Assigning Keyboard Shortcut to Macro

cowe6453

New Member
Joined
Nov 14, 2013
Messages
14
Hi,

I currently have a command button to run a macro that hides unwanted rows but want to assign a keyboard short i.e. "Ctrl a". Do I need to edit the following code in order to assign the shortcut or does it involve messing with the properties? I am just starting to learn basic VBE and macros so any help would be much appreciated. Thanks

Private Sub CommandButton1_Click()


Range("C31").Select
Do While ActiveCell.Value <> ""
ActiveCell.Select
If ActiveCell.Value = False Then
ActiveCell.EntireRow.Hidden = True
End If
ActiveCell.Offset(1, 0).Select
Loop


End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You could go to the Developer Tab, click Record Macro. There it will prompt for the keyboard shortcut where you add Cntrl+A
Then click Stop macro
Go to the VB editor.
Your new macro will be in a module
You will see this;
Code:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+A
'
End Sub

Then paste your code;
Code:
Range("C31").Select
Do While ActiveCell.Value <> ""
ActiveCell.Select
If ActiveCell.Value = False Then
ActiveCell.EntireRow.Hidden = True
End If
ActiveCell.Offset(1, 0).Select
Loop

directly under this line;

Code:
' Keyboard Shortcut: Ctrl+A



Also, remove the " ' " that appears in the line above End Sub

Then close the VB editor
 
Last edited:
Upvote 0
Also worth noting, if you are using 2007+, the macros feature under the developer tab (if you have enabled it under Excel Options - Popular) will allow you to do the assign keyboard shortcuts to subs without going into the vb editor. Just click Macros, then select the macro name and click the options button. This does assume you have entered the macro as Jim suggested above.

Good Luck.
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,039
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top