Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Format A TextBox For A Phone Number

Greetings,

I am trying to format a TextBox on a UserForm to display a phone
number in xxx-xxx-xxxx format when I exit the TextBox.

Any help would be appreciated.

TIA

-Minitman
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Format A TextBox For A Phone Number

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(textbox1.text,"000-000-0000")
End Sub

--
Regards,
Tom Ogilvy


"Minitman" wrote in message
...
Greetings,

I am trying to format a TextBox on a UserForm to display a phone
number in xxx-xxx-xxxx format when I exit the TextBox.

Any help would be appreciated.

TIA

-Minitman



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Format A TextBox For A Phone Number

Thanks Tom,

That will do the trick.

-Minitman

On Tue, 8 Feb 2005 11:15:44 -0500, "Tom Ogilvy"
wrote:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(textbox1.text,"000-000-0000")
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Format A TextBox For A Phone Number

Try this-Tested!!:

Private Sub TextBox1_Change()
If Len(TextBox1.Text) = 3 Then
TextBox1.Text = TextBox1.Text & Chr(45)
End If
If Len(TextBox1.Text) = 7 Then
TextBox1.Text = TextBox1.Text & Chr(45)
End If
TextBox1.MaxLength = 12
End Sub

Should you want to apply this to a number of TextBoxes, use the modified
version:

Private Sub FormatText()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
ctl.MaxLength = 12
If Len(ctl.Text) = 3 Then
ctl.Text = ctl.Text & Chr(45)
End If
If Len(ctl.Text) = 7 Then
ctl.Text = ctl.Text & Chr(45)
End If
End If
Next
End Sub
"Minitman" wrote in message
...
Greetings,

I am trying to format a TextBox on a UserForm to display a phone
number in xxx-xxx-xxxx format when I exit the TextBox.

Any help would be appreciated.

TIA

-Minitman



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to format the phone number Michelle Excel Worksheet Functions 2 March 5th 10 11:49 PM
format a cell with a phone number - how? Martin ©¿©¬ @nohere.net Excel Discussion (Misc queries) 4 March 29th 09 03:45 PM
phone number format [email protected] Excel Worksheet Functions 2 January 21st 08 10:40 AM
phone number format Omar Excel Discussion (Misc queries) 3 January 21st 08 10:20 AM
how do I add phone number format as a permanent custom format? frustratedagain Excel Discussion (Misc queries) 3 February 4th 06 03:52 AM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"