![]() |
Validation in userform
In a textbox of my userform only the comma and digits are allowed. But, the
user must not be able to make long entry: such as 1,65647. Only two digits AFTER the comma are allowed. Digits on the third position must be deleted. Can someone help? |
Validation in userform
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1 Select Case KeyAscii Case 44: ' comma If Len(.Text) - Len(Replace(.Text, ",", "")) = 1 Then MsgBox "Too many commas" KeyAscii = 0 End If Case 48 To 57: '0-9 If InStr(.Text, ",") 0 Then If InStr(.Text, ",") = Len(.Text) - 2 Then MsgBox "Only 2 dec places" KeyAscii = 0 End If End If End Select End With End Sub -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Gert-Jan" wrote in message ... In a textbox of my userform only the comma and digits are allowed. But, the user must not be able to make long entry: such as 1,65647. Only two digits AFTER the comma are allowed. Digits on the third position must be deleted. Can someone help? |
Validation in userform
Thanks, this works great!!
"Bob Phillips" schreef in bericht ... Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) With Me.TextBox1 Select Case KeyAscii Case 44: ' comma If Len(.Text) - Len(Replace(.Text, ",", "")) = 1 Then MsgBox "Too many commas" KeyAscii = 0 End If Case 48 To 57: '0-9 If InStr(.Text, ",") 0 Then If InStr(.Text, ",") = Len(.Text) - 2 Then MsgBox "Only 2 dec places" KeyAscii = 0 End If End If End Select End With End Sub -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "Gert-Jan" wrote in message ... In a textbox of my userform only the comma and digits are allowed. But, the user must not be able to make long entry: such as 1,65647. Only two digits AFTER the comma are allowed. Digits on the third position must be deleted. Can someone help? |
All times are GMT +1. The time now is 12:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com