Results 1 to 5 of 5

Thread: How do I run a macro every time key pressed
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jul 2005
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default How do I run a macro every time key pressed

    Hi

    I found this macro on here that runs a macro when the delete key is pressed on book opening.

    What Iím trying to do if poss is to have this but to be able to have it numerous times. I.E click on delete key run macro then push delete key run another macro and so on....

    Can I do this? Apologies script not highlighted but just typing on I phone.

    Private Sub Workbook_Open()
    Application.OnKey "{DELETE}", "MyMacro"
    End Sub

  2. #2
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,886
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: How do I run a macro every time key pressed

    Why not put all the macro calls in the "My Macro" code, eg

    Code:
    Sub My Macro()
    Call My 1st Macro
    Call My 2nd Macro
    Call My 3rd Macro
    end Sub
    Last edited by Michael M; Sep 24th, 2019 at 02:58 AM.
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  3. #3
    Board Regular
    Join Date
    Jul 2005
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How do I run a macro every time key pressed

    Did think that but i want to be able to view worksheet and compare data before moving on and thus why wait until I press button to move on.
    Or do you mean putting this as separate macros within one big macro?

    Application.OnKey "{DELETE}", "MyMacro"
    Last edited by ghrek; Sep 24th, 2019 at 03:04 AM.

  4. #4
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,886
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: How do I run a macro every time key pressed

    do you mean putting this as separate macros within one big macro?
    Yes....Can't really see how you can do it any other way !!
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  5. #5
    MrExcel MVP FormR's Avatar
    Join Date
    Aug 2011
    Location
    UK
    Posts
    6,113
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    2 Thread(s)

    Default Re: How do I run a macro every time key pressed

    I suppose you could use a public variable to keep track of how many times you'd pressed the button and then call the appropriate macro - something like this for example.

    Code:
    Public MyCounter As Long
    
    
    Sub MyMacro()
    Select Case MyCounter
        Case 0: Call MyMacro1
        Case 1: Call MyMacro2
        Case 2: Call MyMacro3
        Case 3: Call MyMacro4
    End Select
    MyCounter = MyCounter + 1
    End Sub
    [code]your code[/code]

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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