Formatting a text box in a form

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

I have an input box for users to enter a 10 digit
telephone number (including area code).

Is there a way to format the text box so the hyphens are
automatically entered after the user keys in the 10
digits. I need the number to appear as follows:
123-456-7890

Thanks for the help.
 
Hi JT

Try the Exit event of the textbox in the userform module

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Or Len(TextBox1) > 10 Then Cancel = True
Me.TextBox1.Text = Format(TextBox1, "000-000-0000")
End Sub
 

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