Control content of text boxes on a userform

A

Angela

I am aware of data validation in cells to force text or
numeric values. Is there a way of doing this in a
userform text box?

You can assign the value of a textbox to a numeric
variable, but this is too late when you have clicked the
OK button

Any help gratefully received
 
M

mangesh_yadav

well, you could try the same thing for OnChange event for tha
particular testbox. So whatever validation you do after clicking OK
you do it in the OnChange event

- Manges
 
M

Michel Pierron

Hi Angela,
A way of making:
Private Sub TextBox1_Change()
Me.TextBox1 = CleanChain(Me.TextBox1)
End Sub

Private Function CleanChain(Chain As String) As String
Const Cars As String = "0123456789,."
Dim L As String * 1, i As Integer
For i = 1 To Len(Chain)
L = Mid(Chain, i, 1)
Select Case L
Case ",", "."
L = Application.International(xlDecimalSeparator)
If InStr(1, CleanChain, L) Then GoTo 1
End Select
If InStr(1, Cars, L) Then CleanChain = CleanChain & L
1: Next i
End Function

MP
 
A

Angela

Thanks I'll give this a try
Angela
-----Original Message-----
Hi Angela,
A way of making:
Private Sub TextBox1_Change()
Me.TextBox1 = CleanChain(Me.TextBox1)
End Sub

Private Function CleanChain(Chain As String) As String
Const Cars As String = "0123456789,."
Dim L As String * 1, i As Integer
For i = 1 To Len(Chain)
L = Mid(Chain, i, 1)
Select Case L
Case ",", "."
L = Application.International(xlDecimalSeparator)
If InStr(1, CleanChain, L) Then GoTo 1
End Select
If InStr(1, Cars, L) Then CleanChain = CleanChain & L
1: Next i
End Function

MP

"Angela" <[email protected]> a écrit dans le message de



.
 
Top