I want to make a number into a shortcut that can run a macro

bluezero2x

New member
Joined
May 23, 2015
Messages
6
Reaction score
0
Points
0
Basically, i want to be able to hit 1 and have a macro run. I found this code, though i dont know how to bind it to a macro.

So if i make a simple macro like;


Sub Adding()
'
' Adding Macro
'


'
ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]"
Range("D2").Select
End Sub


Then make a new module, and put in;

Sub test()MsgBox "Hello"End SubSub Shortcut1()Application.OnKey "1", "test"End Sub

How do i bind the macro to this hotkey?
 
If we have:

Code:
Sub marine()
   MsgBox "Under the sea"
End Sub

First run this:

Code:
Sub SetHotKey()
   Application.OnKey "1", "marine"
End Sub

to set the hotkey and run this:

Code:
Sub Reset1()
   Application.OnKey "1", "marine"
End Sub
to un-set the hotkey

Be aware that only the "top-row" 1 will be active, the 1 on the numeric keypad is still available for data entry.
 
That happens when you ask in three forums within 10 minutes of each other with no reason to think you're doing anything wrong. Sadly, of the four or five people who actually bothered to reply among ALL THREE FORUMS, only two people actually gave any useable information, which makes me feel i made the right choice in the first place. (Incidentally, having read the post you gave me NoS, I feel even more secure in my choice to crosspost, so i will thank you at least for that help.)
 
Thank you for your reply Gary!

Heres what ive puzzled out so far.

"Thisworkbook" contains the code
Code:
Sub Workbook_Open()
Application.OnKey "{97}", "test"


Application.OnKey "{98}", "test2"


Application.OnKey "{99}", "Test3"


End Sub

And module one contains..
Code:
Sub test()
MsgBox "Well, finally"


End Sub
Sub test2()


    Range("A1").Select


End Sub


Sub test3()
'
' Add Macro
'


Range("C2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]+RC[-2]"
    Range("C3").Select
End Sub

Ive managed to get them all to work. The numbers 97-99 apply to the number pad 1-3. My issue now is, i want test3 to add the two columns to the left anywhere on the spreadsheet. This may not be possible, but thats what im looking for. Thoughts?
Also, what does sub reset do?


cross posted with slight changes:
http://www.mrexcel.com/forum/excel-q...umber-key.html
http://www.ozgrid.com/forum/showthread.php?t=194887
http://www.excelforum.com/excel-prog...rtcut-key.html
 
Last edited:
Back
Top