ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Form Text Box (https://www.excelbanter.com/excel-programming/402145-form-text-box.html)

krc547

Form Text Box
 
How do i get a text box on a form to only allow a certain way to fill the box
in. Such as a text box for a phone number and I want the input to be limited
to look like the following:

(555)555-5555

JLGWhiz

Form Text Box
 
This works in a worksheet range:

Sub Numbfmt()
Range("C3").NumberFormat = "(###)###-###0"
End Sub

"krc547" wrote:

How do i get a text box on a form to only allow a certain way to fill the box
in. Such as a text box for a phone number and I want the input to be limited
to look like the following:

(555)555-5555


John

Form Text Box
 
untested but something like this may work:

Private Sub TextBox1_Change()
If IsNumeric(TextBox1.Text) Then
If Len(TextBox1.Text) = 10 Then
mynum = Format(TextBox1.Text, "(###)###-###0")
TextBox1.Text = mynum
End If
End If
End Sub
--
JB


"krc547" wrote:

How do i get a text box on a form to only allow a certain way to fill the box
in. Such as a text box for a phone number and I want the input to be limited
to look like the following:

(555)555-5555



All times are GMT +1. The time now is 11:40 PM.

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