Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box validation
Hi everyone,
I want to validate a textbox in vba. I want a textbox to accept only numbers, not text. I would really appreciate any kind of help or hint Lefkios |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box validation
Test it on input
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 48 To 57: Case Else: KeyCode = 0 End Select End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "kastoras" wrote in message ... Hi everyone, I want to validate a textbox in vba. I want a textbox to accept only numbers, not text. I would really appreciate any kind of help or hint Lefkios |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box validation
Hi Bob,
Thanks a lot for your answer. works but not exactly as i want it to be. a) i cannot delete what i've already typed in. Backspace is not working or DELETE key. b) I also want to accept decimals. i.e 10.3 Again thanks a lot for the qick reply Lefkios "Bob Phillips" wrote: Test it on input Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 48 To 57: Case Else: KeyCode = 0 End Select End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "kastoras" wrote in message ... Hi everyone, I want to validate a textbox in vba. I want a textbox to accept only numbers, not text. I would really appreciate any kind of help or hint Lefkios |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box validation
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii Case 8 To 10, 13, 27 'Control characters Case 45, 46 ' negative and period If KeyAscii = 45 Then ' hypen/negative If Len(Trim(TextBox1.Text)) 1 Then Beep KeyAscii = 0 End If End If Case 48 To 57 'numbers Case Else 'Discard anything else Beep KeyAscii = 0 End Select End Sub if you use comma (instead of period) as a decimal separator, I believe it is keycode 44 -- Regards, Tom Ogilvy "kastoras" wrote in message ... Hi Bob, Thanks a lot for your answer. works but not exactly as i want it to be. a) i cannot delete what i've already typed in. Backspace is not working or DELETE key. b) I also want to accept decimals. i.e 10.3 Again thanks a lot for the qick reply Lefkios "Bob Phillips" wrote: Test it on input Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 48 To 57: Case Else: KeyCode = 0 End Select End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "kastoras" wrote in message ... Hi everyone, I want to validate a textbox in vba. I want a textbox to accept only numbers, not text. I would really appreciate any kind of help or hint Lefkios |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box validation
Tom,
Thank you very very much. It works like a charm! "Tom Ogilvy" wrote: Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 8 To 10, 13, 27 'Control characters Case 45, 46 ' negative and period If KeyAscii = 45 Then ' hypen/negative If Len(Trim(TextBox1.Text)) 1 Then Beep KeyAscii = 0 End If End If Case 48 To 57 'numbers Case Else 'Discard anything else Beep KeyAscii = 0 End Select End Sub if you use comma (instead of period) as a decimal separator, I believe it is keycode 44 -- Regards, Tom Ogilvy "kastoras" wrote in message ... Hi Bob, Thanks a lot for your answer. works but not exactly as i want it to be. a) i cannot delete what i've already typed in. Backspace is not working or DELETE key. b) I also want to accept decimals. i.e 10.3 Again thanks a lot for the qick reply Lefkios "Bob Phillips" wrote: Test it on input Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 48 To 57: Case Else: KeyCode = 0 End Select End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "kastoras" wrote in message ... Hi everyone, I want to validate a textbox in vba. I want a textbox to accept only numbers, not text. I would really appreciate any kind of help or hint Lefkios |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Validation - Weekend Or text | Excel Worksheet Functions | |||
Text Validation | Excel Programming | |||
Validation (Drop down list vs simple text length validation) | Excel Programming | |||
Validation (Drop down list vs simple text length validation) | Excel Programming | |||
Validation (Drop down list vs simple text length validation) | Excel Programming |