Short key/ hot key for CommandButton

noexcelguru

New Member
Joined
Jan 18, 2011
Messages
40
One of my commandbuttons will every now and then be covered by the FormulaBar, is it possible to assign a short key/ hot key for its function (CTRL+q)?

CommandButton's code:

Private Sub CommandButton3_Click()
Select Case ActiveCell.Interior.ColorIndex
Case xlNone: ActiveCell.Interior.ColorIndex = 3
Case 3: ActiveCell.Interior.ColorIndex = 6
Case 6: ActiveCell.Interior.ColorIndex = 10
Case 10: ActiveCell.Interior.ColorIndex = xlNone
End Select
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
As i'm bumping this one back up, i'll also clarify my problem; One of my commandbuttons will every now and then be hidden under the FormulaBar, is it possible to assign a short key/ hot key (CTRL+q) wich will run the CommandButton's code/ function?
 
Upvote 0
If it's an ActiveX button, then you can set a letter as its accelerator and use Alt+letter to run the button code. (normally you would choose a letter in the button caption, which will then be underlined). If it's a forms button, then just assign a shortcut key to its macro in the macros dialog.
 
Upvote 0
Thanks for your reply.
Doesn't seem to work, probably because of macro? When i click the button the cell remains blanc (xlnone), however if i click the button several times fast, i see the colors flashing, but not 'sticking' to the cell.

Macro:
Sub Makro1()
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Selection.Interior.ColorIndex = 6
Selection.Interior.ColorIndex = 10
Selection.Interior.ColorIndex = xlNone
End Sub

As i wrote above, i believe the macro/ code is wrong as it looks to just 'run through' the colors rather than selecting one and end. Any suggestions? Isn't it possible to assign a macro or code to a VB CommandButton rather than an ActiveX?
 
Upvote 0
Why have you changed the code? The original code was fine.
 
Upvote 0
It did work with the original code :) Thanks, Roya
I thought i had to use different codes for macros (i'm not that familiar with excel as you probably have understood)

So it isn't possible to assign hot keys to VB CommandButtons?
 
Upvote 0
It is, using the Accelerator as I mentioned, but you have to use Alt+letter rather than Ctrl+ or Ctrl+Shift+ as you can with macros.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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