How do I run a macro every time key pressed

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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:
Upvote 0
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:
Upvote 0
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 !!
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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