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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
What do you mean by the key codes?

Do you mean the ASCII codes?

They are for 48 to 57 for 0-9 respectively.
 

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
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.
 

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,225
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.
 

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
Thanks again,

It is in a userform where only numbers are to be entered.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,334
Messages
5,601,012
Members
414,421
Latest member
tonybear1994

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
Top