mikewild2000 > said:
I have a little VB code in a "worksheet_change" decalration.
I am trying to add code that will move the focus to C11 once the user
has inputted 3 digits in cell J7
I hope somebody can help.
It may be possible to do this using Windows API calls to monitor the
keyboard, but it'd be extremely intrusive and fragile.
It's also possible to do this for the numeral keys on the standard
typewriter keypad, i.e., the row of keys above the QWERTY row of keys. It
requires an system like so.
Option Explicit
Private ds3 As String
Sub foo()
ds3 = ""
Application.OnKey "-", "unfoo"
Application.OnKey "0", "dgt0"
Application.OnKey "1", "dgt1"
Application.OnKey "2", "dgt2"
Application.OnKey "3", "dgt3"
Application.OnKey "4", "dgt4"
Application.OnKey "5", "dgt5"
Application.OnKey "6", "dgt6"
Application.OnKey "7", "dgt7"
Application.OnKey "8", "dgt8"
Application.OnKey "9", "dgt9"
MsgBox "foo'ed"
End Sub
Sub unfoo()
If ds3 <> "" Then ActiveCell.Formula = "'" & ds3
Application.OnKey "0"
Application.OnKey "1"
Application.OnKey "2"
Application.OnKey "3"
Application.OnKey "4"
Application.OnKey "5"
Application.OnKey "6"
Application.OnKey "7"
Application.OnKey "8"
Application.OnKey "9"
MsgBox "unfoo'ed"
End Sub
Sub dgt(n As Long)
If Len(ds3) >= 3 Then dgtflsh True 'just in case
ds3 = ds3 & Format(n)
dgtflsh (Len(ds3) >= 3)
End Sub
Sub dgtflsh(s As Boolean)
ActiveCell.Formula = "'" & ds3
If s Then
ds3 = ""
ActiveCell.Offset(1, 0).Activate
End If
End Sub
Sub dgt0(): dgt 0: End Sub
Sub dgt1(): dgt 1: End Sub
Sub dgt2(): dgt 2: End Sub
Sub dgt3(): dgt 3: End Sub
Sub dgt4(): dgt 4: End Sub
Sub dgt5(): dgt 5: End Sub
Sub dgt6(): dgt 6: End Sub
Sub dgt7(): dgt 7: End Sub
Sub dgt8(): dgt 8: End Sub
Sub dgt9(): dgt 9: End Sub
I don't believe OnKey supports the numeral keys in the number keypad.
It may be better & easier to train your users how to use the [Enter] key.