Record button press on worksheet change

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
Is there a way to record which button the user pushed?

Eg, if the user pushes delete in a certain range, clear a certain other range.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Application
a = Application.OnKey([Del], MyChange)
End Sub
 
Private Function MyChange()
MsgBox "Hey"
End Function

This returns "Expected function or variable" for the OnKey part... even though it's available to VBA through intellisense.


...And when I use this, the UDF triggers no matter what I type, and then I get "Object doesn't support property or method".

Code:
a = Application.Worksheetfunctions.OnKey([del], MyChange)
 
Last edited:
Upvote 0
Glory,

Better not to use the code in the link as it is not stable in XL2007 and can potentially crash excel. I'll try writing a new and more stable code to simulate an OnKey event for cells later on.

As for your code I think it should be like this :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Call Application.OnKey("{DEL}", Me.CodeName & ".MyChange")
End Sub
 
Private Function MyChange()
    MsgBox "Hey"
End Function
 
Upvote 0
Thank you very much...

I'm using "Center across selection", which causes some text to appear to be located in a cell it's not. So when people click the cell they think the text is in and try to delete it, now the text will go away.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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