ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Control content of text boxes on a userform (https://www.excelbanter.com/excel-programming/305947-control-content-text-boxes-userform.html)

Angela[_5_]

Control content of text boxes on a userform
 
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

mangesh_yadav[_38_]

Control content of text boxes on a userform
 
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

--
Message posted from http://www.ExcelForum.com


Michel Pierron[_2_]

Control content of text boxes on a userform
 
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" a écrit dans le message de
...
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




Angela[_5_]

Control content of text boxes on a userform
 
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" a écrit

dans le message de
...
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



.



All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com