Results 1 to 5 of 5

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

  1. #1

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



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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?

  2. #2
    Seeker Gary's Student's Avatar
    Join Date
    Mar 2014
    Location
    Lakehurst, NJ, USA
    Posts
    5
    Articles
    0
    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.

  3. #3
    Magician NoS's Avatar
    Join Date
    Jan 2013
    Location
    British Columbia
    Posts
    751
    Articles
    0
    Excel Version
    Excel 2010 64bit
    Would appear you're not much into reading the rules at the various forms.

    If you read nothing else, at least read this.

    cross posted:
    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

  4. #4
    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.)

  5. #5
    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 by bluezero2x; 2015-05-24 at 08:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •