I am trying to trap the key entered into an excel spreadsheet. Does anyone know how I can accomplish that?
Thank you!
Printable View
I am trying to trap the key entered into an excel spreadsheet. Does anyone know how I can accomplish that?
Thank you!
Any key press, a specific key, or entry in a specific cell?
Please give us some more detail on what you are trying to achieve.
I want to trap any key that is pressed on a given worksheet.
I know there is a keypress and keyup and keydown events, but I don't believe they apply to worksheets, only forms.
There is a Worksheet Change event that might serve your needs. If a cell is changed (by keyboard entry, paste, or vb program), the event fires exposing the cell address. You could then find out the contents of the cell to determine what the keystrokes were. Kind of indirect, but maybe good enough.
VB Code:
Private Sub Worksheet_Change(ByVal target As Excel.Range) Debug.Print target.value End Sub
This doesn't work for the delete key. It doesn't trigger the change event when the delete key is pressed.
Any other ideas?
There are no Keypress, keyup or keydown events for a cell.
What are you trying to do?
When the delete key is pressed on a particular sheet meeting certain criteria, I want to basically control what they are trying to delete and only allow it under certain conditions.
You may have to end up protecting the sheet and if its a certain user then unprotect it?