ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   formatting text in TextBox in UserForm (https://www.excelbanter.com/excel-programming/281795-formatting-text-textbox-userform.html)

Kevin

formatting text in TextBox in UserForm
 
I'd like users to be able to enter single digit numbers into a TextBox but have the code format this as a four-character text string, e.g., "0000". Is this possible?

Thanks.


Kevin

Tom Ogilvy

formatting text in TextBox in UserForm
 
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(TextBox1.Value) Then
If Len(Trim(TextBox1.Value)) = 1 Then
TextBox1.Value = Format(CLng(TextBox1.Value), "0000")
Else
MsgBox "Single Digit Numbers only"
TextBox1.Value = ""
Cancel = True
End If
Else
MsgBox "Entry must be numeric and single digit"
TextBox1.Value = ""
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy

"Kevin" wrote in message
...
I'd like users to be able to enter single digit numbers into a TextBox but

have the code format this as a four-character text string, e.g., "0000". Is
this possible?

Thanks.


Kevin




Kevin

formatting text in TextBox in UserForm
 
Thanks Tom. It works like a charm.

Kevin
-----Original Message-----
Private Sub TextBox1_Exit(ByVal Cancel As

MSForms.ReturnBoolean)
If IsNumeric(TextBox1.Value) Then
If Len(Trim(TextBox1.Value)) = 1 Then
TextBox1.Value = Format(CLng

(TextBox1.Value), "0000")
Else
MsgBox "Single Digit Numbers only"
TextBox1.Value = ""
Cancel = True
End If
Else
MsgBox "Entry must be numeric and single digit"
TextBox1.Value = ""
Cancel = True
End If
End Sub

--
Regards,
Tom Ogilvy

"Kevin" wrote in

message
...
I'd like users to be able to enter single digit numbers

into a TextBox but
have the code format this as a four-character text

string, e.g., "0000". Is
this possible?

Thanks.


Kevin



.



All times are GMT +1. The time now is 03:05 AM.

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