Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Textbox value
Hi
How can you restrict users from only entering numbers in a textbox; and if text was entered a error message will be displayed. Thanks Sham |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Textbox value
Sham,
Assuming a userform, this will do as you ask Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) With Me.TextBox1 If Not IsNumeric(.Text) Then .SelStart = 0 .SelLength = Len(.Text) .SetFocus Cancel = True MsgBox "Invalid data" End If End With End Sub An alternative is to trap the input, and only allow numerics Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii < 48 Or KeyAscii 57 Then Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True End If End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Shamsul" wrote in message ... Hi How can you restrict users from only entering numbers in a textbox; and if text was entered a error message will be displayed. Thanks Sham |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Calculate Textbox value based on another textbox value.doc | Excel Discussion (Misc queries) | |||
Calculate Textbox value based on another textbox value | Excel Discussion (Misc queries) | |||
Textbox | Excel Discussion (Misc queries) | |||
TextBox | Excel Programming | |||
UserForm TextBox to ActiveSheet TextBox over 256 characters | Excel Programming |