Key Code ?

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
Can someone please tell me the key codes for the numeric keys 0 - 9.

Ideally a link to a list would be ideal but if not just the codes for key 0-9.


Many thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
What do you mean by the key codes?

Do you mean the ASCII codes?

They are for 48 to 57 for 0-9 respectively.
 
Upvote 0
For future reference, you can find this out quickly by using the Immediate Window, and the ASC function. Type:

?ASC("0")

in the immediate window, and hit enter. You can do this for all of the keys.
 
Upvote 0
Thanks for the help.

I still can't use the Numeric keypad though.

I have this code:

Private Sub SurveyedTextBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)


' Allows Delete or Enter keys to be processed normally
If KeyCode > 31 Then


' If not 1, 2 or 3, or a number has already been
' entered, don't accept additional input


If KeyCode < 48 Or KeyCode > 57 Or Len(PolingTextBox.Text) > 3 Then
KeyCode = 0
End If


End If
End Sub

but only works on the Number keys NOT on the Numeric keypad numbers.

Any ideas?
 
Upvote 0
Dave

What are you actually trying to do?

Is it some sort of validation/restriction on what the user enters in the textbox?

Perhaps you could use another event.
 
Upvote 0
Those "10-key" numbers need to be addressed individually by their associated OnKey commands. Please specify if this textbox is in a userform or embedded on a worksheet.
 
Upvote 0
Dave

Why not use either the Change or Exit event to check the user has entered a number?

I prefer using Exit:

Code:
Private Sub SurveyedTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not IsNumeric(SurveyedTextBox.Value) Then
        MsgBox "Please enter a numeric value."
        Cancel = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

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