Control content of text boxes on a userform

  • Thread starter Thread starter Angela
  • Start date Start date
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
 
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
 
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
 
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



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top