I have a userform with a text box and would like to have the format be in (###)###-#### format. Can someone help me with this code? Thanks in advance.
I have a userform with a text box and would like to have the format be in (###)###-#### format. Can someone help me with this code? Thanks in advance.
![]()
Please Login or Register to view this content.
Entia non sunt multiplicanda sine necessitate
Thanks, but the textbox now will default to 9725551215. Is there a way to have the box blank and let the user enter numbers that will automatically follow the (xxx)xxx-xxxx format? Thanks.
Hi aduma
Perhap this![]()
Please Login or Register to view this content.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please mark your Thread as SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hello aduma ,
This macro will format the phone number as you type. This example uses TextBox1 but can be used for any text box. Just copy the code between the Sub and End Sub statements and paste it in the KeyPress event for the text box you are using.
![]()
Please Login or Register to view this content.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
@Leith Ross
Wow...been looking for this for some time. Thank you.
Hello John,
Glad you like it. I have wanted to write this for some time but the time never seemed right. It isn't perfect. It stills a need a tweak or two to deal with backspaces.
Hi Leith
Well, if you get a better mouse trap please let us know. I've already incorporated your code into our Association's Data Base code and it's been appropriately attributed.
Thanks again.
Last edited by jaslake; 04-18-2012 at 11:18 PM.
Hello John,
I will keep you posted on any updates. Thanks for the credit.
I to just used this code to format a phone text box and it works great for me too. Thanks a millon!
Hi williesmith2008
Yes this is a neat bit of Code...please make certain you give kudos to Mr Ross, the Author. Click on the Star at the bottom left of his post. Style points are always appreciated...it's how we get "paid".
I know this is a bit old but I was wondering if this could be modified for international numbers?
Cheers,
Gino
Hello gino,
Why not? Do you have a list of list of numbers and how they should be formatted? If you have a workbook that would be better.
hi Leith,
Wow - thanks - if you could take a try at this - that would be great. I don't have a workbook on this yet, but am looking to build out a userform where based on the country selected, maybe get the phone numbers (mobile & land) to take on the right format.
So for example, I've got a Germany phone that looks like this - +49 89 3706 17067
Australia or Japan - look like +61 2 9293 5666
And in India a land line looks like +91 (080) 404440062 while a cell phone looks like 91 9620708001
So definitely the country code +91 for example and then I guess (not sure how you'd work magic on this) but either 2 digits and a space or 1 digit and a space (from the examples above).
Anyway - saw what you created and for the US, it's a big winner for sure and naturally, I thought - hmmm... how about non-US phone number formats!
Cheers,
Gino
Hello gino59,
This is will take some time. International telephone numbers do have a preferred format but it is not always followed by everyone.
This make it more difficult to parse. You may have to ask your users to enter the number using the preferred international format.
Once that piece is in place then reset will be much easier.
Hey Leith,
Yeah - no worries - you're right - it is problematic and I just figured I'd throw it out there to see if you had already had something in mind. I might take a stab at creating a country list and the corresponding format. Then the trick would be how to get the textbox to first look up the country value (found elsewhere on the userform) and then apply the corresponding phone format to the phone textbox.
Or as you mentioned - let the d@m!n users figure it out!!!
Cheers,
Gino
Jon, welcome to the forum
Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.
If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.
Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks