View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to create a check to allow user to input numerics from the num

Yes, 8 is a backspace.

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
Just wondering... what's the best way to do a backspace ?

I figure the KeyCode = 8 for backspace.

Tom Ogilvy wrote:
Put in a userform with Textbox1 and Label1

Put in code like this:

Private Sub TextBox1_Change()
TextBox1.Value = ""
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal
Shift As Integer)
Label1.Caption = KeyCode
End Sub

now test the keys - with numlock on and off. Also look at other keys on
the keyboard.

Use a select case statement to sort them out.

--
Regards,
Tom Ogilvy


" wrote:

Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
' Pass through only digits.
If KeyCode < 48 Or KeyCode 57 Then
KeyCode = 0
Beep
End If

' As I found out the numerics from the numeric pad range from 0x60 to
0x69
' Could someone show me how to set up a valid check for them ?
If KeyCode < "0x60" Or KeyCode "0x69" Then
KeyCode = 0
Beep
End If


End Sub