ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic for Excel (https://www.excelbanter.com/excel-programming/376006-visual-basic-excel.html)

amit

Visual Basic for Excel
 
I have made a user form consisting of various Text Boxes. Can I control the
entry type in the Box? eg I would like that only integers be entered in the
Text Box.

Bob Phillips

Visual Basic for Excel
 
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 45 'negative
If Len(Trim(TextBox1.Text)) 1 Then
Beep
KeyAscii = 0
End If
Case 46 'period
If InStr(TextBox1.Text, ".") 0 Then
Beep
KeyAscii = 0
End If
Case 48 To 57 'numbers
If InStr(TextBox1.Text, ".") 0 Then
If Len(TextBox1.Text) InStr(TextBox1.Text, ".") + 1 Then
Beep
KeyAscii = 0
End If
End If
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Amit" wrote in message
...
I have made a user form consisting of various Text Boxes. Can I control

the
entry type in the Box? eg I would like that only integers be entered in

the
Text Box.





All times are GMT +1. The time now is 04:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com