xl.format.phone turns a US number into (512) 555-0148. The 555 prefix on this page is the fictional range, 555-0100 through 555-0199. A real sheet uses the same steps on a real number.
512-555-0148, 5125550148, and 1 512 555 0148 all become that display. Parentheses, hyphens, spaces, dots, and a plus sign are stripped. If 11 digits remain and the first is 1, the country code is dropped. Any other length comes back unchanged, which is how an extension stays out of the formatted string.
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA.
The workbook that keeps a column of these numbers is the sales pipeline tracker.
The formatted display
=xl.format.phone(B1)| A | B | |
|---|---|---|
| 1 | Raw | 512-555-0148 |
| 2 | Phone | (512) 555-0148 |
Store the source as text. A 10-digit value can survive as a number. A longer value loses digits past Excel’s 15-digit precision, and the formatted result is then wrong in a way the cell does not flag.
Digits only
xl.digits.only keeps each digit and drops the rest. The result is text, so a leading zero would survive. This sample has no leading zero.
=xl.digits.only(B1)| A | B | |
|---|---|---|
| 1 | Raw | 512-555-0148 |
| 2 | Digits | 5125550148 |
| 3 | Length | 10 |
5125550148 has length 10, which is the length xl.format.phone is willing to shape. Letters in a vanity number stay in the digits-only result and usually make the phone function return the original text.
TEXT, when the cell is already a number
TEXT does not clean punctuation. It prints a number with a format code. A 10-digit number that is already in the cell can use (000) 000-0000.
=TEXT(B1,"(000) 000-0000")| A | B | |
|---|---|---|
| 1 | Number | 5125550148 |
| 2 | Text | (512) 555-0148 |
The result is text. SUM ignores it, the same way SUM ignores a date that TEXT has turned into words. TEXT does not drop a leading 1 and it does not strip hyphens from a text cell. Use it for a clean numeric value. Use xl.format.phone when the cell still has punctuation or a country code.