Phone number with area code mask number format.

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
704
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I need to set a mask (cell number format) to do this:
Phone number can be with area code (lenght): 10 (2+8), 11 (2+9) or, without area code: 8 or 9. (non-us format)
Some aleatory (non real) numbers just for example:
12345678 result "1234-5678"
1212345678 result "(12) 1234-5678
123456789 result "12345-6789"
12123456789 result "(12) 12345-6789"
How can I do this?
Thanks
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You can set individual Custom formats but if you have a column of these different number formats I can't see that working.

You could format them into another column with CHOOSE

AB
1PhonePhone Formatted
2123456781234-5678
31212345678(12) 1234-5678
412345678912345-6789
512123456789(12) 12345-6789

<tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
B2=CHOOSE((LEN(A2)-7),TEXT(A2,"0000-0000"),TEXT(A2,"00000-0000"),TEXT(A2,"(00) 0000-0000"),TEXT(A2,"(00) 00000-0000"))

<tbody>
</tbody>

<tbody>
</tbody>

Otherwise I think you'll have to use VBA. I'm sure a VBA expert will be along shortly.
 
Upvote 0
I will save this solution by formula, but the initial idea is just a "numberformat" mask.
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top