79704104

Date: 2025-07-16 22:58:41
Score: 2
Natty:
Report link
Thanks for your answer. I included the curly braces and got some of my work completed.

Overall, what I am trying to accomplish is to igore all keypresses except numerals 0-9. The full code of my module is below, and my spreadsheet output is below that. The OnKey now works for the first (numerically) code that appears to be treated as a control code ("%") by triggering the On Error Go To, but fails to work the second time a 'control code' is encountered. Is my error processing in error or is something else happening? Why did the On Error only take effecrt once?

Option Explicit
Dim KeyPressed As String
Dim i As Integer

Sub Test()
For i = 33 To 127
    If i >= 48 And i <= 57 Then GoTo Nexti ' Skip 0-9
    KeyPressed = Chr(i)
    On Error GoTo OnKeyFailed
    Application.OnKey KeyPressed, "IgnorThisPress"
    Range("G" & i) = i
    Range("H" & i) = Chr(i)
    Range("I" & i) = "Accepted: "
    GoTo Nexti
    
OnKeyFailed:
    KeyPressed = "{" & KeyPressed & "}"
    Range("G" & i) = i
    Range("H" & i) = Chr(i)
    Range("I" & i) = "Not Accepted: "
    Application.OnKey KeyPressed, "IgnorThisPress"
    
Nexti:

Next i

End Sub





End Sub

Sub IgnorThisPress()
MsgBox "Ignor this key."
End Sub

Sub ResetTest()
For i = 33 To 127
    If i >= 48 And i <= 57 Then GoTo Nexti ' Skip 0-9
    KeyPressed = Chr(i)
    On Error GoTo OnKeyFailed
    Application.OnKey KeyPressed
    Range("J" & i) = "Removed: "
    GoTo Nexti
    
OnKeyFailed:
    KeyPressed = "{" & KeyPressed & "}"
    Application.OnKey KeyPressed
    Range("J" & i) = "Removed: "
   
Nexti:




enter image description here Spreadsheet results for G33 through J40

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): I am trying to
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Steve