Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing a Text Box to accept only Numbers
How can I make a text box to accept only numbers or text in a specific format
(eg. for Post Codes) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing a Text Box to accept only Numbers
Assuming the textbox is in a form then in the code behind the form you can
write a short procedure. Assuming the TextBox is called MyTextBox then Sub MyTextBox_Change() if not MyTextBox.Value like "##" then MyTextBox.Value = "" MsgBox "This is not a number", vbOKOnly, "Dont type text" end if end sub This will be triggered as the user types. If you prefer to wait until the user has completed his/her mistake then use _afterUpdate() instead Hope this helps Nick Shinkins "Mihalis" wrote: How can I make a text box to accept only numbers or text in a specific format (eg. for Post Codes) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Forcing a Text Box to accept only Numbers
Why not trap them as input Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 48 To 57 'Nos 0 - 9 Exit Sub Case Else Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True Beep End Select End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Mihalis" wrote in message ... How can I make a text box to accept only numbers or text in a specific format (eg. for Post Codes) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF formula to accept or reject based on numbers entered. | Excel Discussion (Misc queries) | |||
Forcing Text | Excel Discussion (Misc queries) | |||
Format cells to only accept numbers | Excel Discussion (Misc queries) | |||
Forcing Excel to retain red text? | Excel Discussion (Misc queries) | |||
cell format in Excel 2002 SP3 will not accept long numbers | Excel Worksheet Functions |