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?
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?
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" <[email protected]> wrote in message
news:[email protected]...
> 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?
>
>
Thanks, this works great!!
"Bob Phillips" <[email protected]> schreef in bericht
news:[email protected]...
> 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" <[email protected]> wrote in message
> news:[email protected]...
>> 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?
>>
>>
>
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks