Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default 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?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default 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?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default 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?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data validation within a userform kjenner7 Excel Programming 4 March 9th 06 03:37 PM
userform validation? Mike Excel Programming 1 November 30th 05 07:07 PM
Userform with validation... Mark \(InWales\)[_8_] Excel Programming 3 October 26th 04 07:20 AM
UserForm Date Validation Michael Vaughan Excel Programming 2 September 5th 04 08:45 PM
Userform Validation Todd Huttenstine[_2_] Excel Programming 2 December 13th 03 10:46 PM


All times are GMT +1. The time now is 12:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"