Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a text box (txtphone) in a user form that a user will enter a phone
number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rachel,
place both these procedures behind your form & see if it does what you want. the Exit routine ensures format is applied after user has updated entry. Hope helpful Private Sub chkmobile_Click() With Me.txtphone .Text = Replace(Replace(.Text, " ", ""), "-", "") If Me.chkmobile.Value = True Then .Text = Format(.Text, "0000-000-000") Else .Text = Format(.Text, "00-0000-0000") End If End With End Sub Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call chkmobile_Click End Sub -- jb "Rachel" wrote: I have a text box (txtphone) in a user form that a user will enter a phone number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi John,
Sorry for the late response - I actually couldn't find my question after posting it!! Your codes worked perfectly, thank you so much!! "john" wrote: Rachel, place both these procedures behind your form & see if it does what you want. the Exit routine ensures format is applied after user has updated entry. Hope helpful Private Sub chkmobile_Click() With Me.txtphone .Text = Replace(Replace(.Text, " ", ""), "-", "") If Me.chkmobile.Value = True Then .Text = Format(.Text, "0000-000-000") Else .Text = Format(.Text, "00-0000-0000") End If End With End Sub Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call chkmobile_Click End Sub -- jb "Rachel" wrote: I have a text box (txtphone) in a user form that a user will enter a phone number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Rachel,
no worries - glad it worked & thanks for feedback. -- jb "Rachel" wrote: Hi John, Sorry for the late response - I actually couldn't find my question after posting it!! Your codes worked perfectly, thank you so much!! "john" wrote: Rachel, place both these procedures behind your form & see if it does what you want. the Exit routine ensures format is applied after user has updated entry. Hope helpful Private Sub chkmobile_Click() With Me.txtphone .Text = Replace(Replace(.Text, " ", ""), "-", "") If Me.chkmobile.Value = True Then .Text = Format(.Text, "0000-000-000") Else .Text = Format(.Text, "00-0000-0000") End If End With End Sub Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call chkmobile_Click End Sub -- jb "Rachel" wrote: I have a text box (txtphone) in a user form that a user will enter a phone number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Assuming you have the default format as mentioned try the below checkbox
click event.. Private Sub chkmobile_Click() txtphone.Text = IIf(chkmobile.Value, "0000-000-000", "00-0000-0000") End Sub If this post helps click Yes --------------- Jacob Skaria "Rachel" wrote: I have a text box (txtphone) in a user form that a user will enter a phone number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If the user type in the phone number before checking mobile then you can use
the below which would change the format of the existing number.. Private Sub chkmobile_Click() txtphone.Text = Format(Replace(txtphone.Text, "-", ""), _ IIf(chkmobile.Value, "0000-000-000", "00-0000-0000")) End Sub If this post helps click Yes --------------- Jacob Skaria "Jacob Skaria" wrote: Assuming you have the default format as mentioned try the below checkbox click event.. Private Sub chkmobile_Click() txtphone.Text = IIf(chkmobile.Value, "0000-000-000", "00-0000-0000") End Sub If this post helps click Yes --------------- Jacob Skaria "Rachel" wrote: I have a text box (txtphone) in a user form that a user will enter a phone number into. The default format of this text box is to be "00-0000-0000". I want them to be able to tick a check box (chkmobile) if the number is a mobile number and the format of txtphone is to change to "0000-000-000". If they then untick chkmobile the format returns to "00-0000-0000". Is this possible? Thanks :) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Check boxes and text strikethrough / color change | Excel Worksheet Functions | |||
How to change the font size for text within check box? | Excel Discussion (Misc queries) | |||
Change Date Format to Specific Text Format When Copying | Excel Discussion (Misc queries) | |||
how do I change the text size of a form check box | New Users to Excel | |||
Automatically change the text color when you check out the checkbo | Excel Discussion (Misc queries) |