Mobile phone number formatting (US/Canada).
This repo includes an Excel VBA module that:
- detects likely phone-number columns by header name (phone/mobile/cell/sms/tel)
- converts vanity letters to digits (e.g.
1-800-FLOWERS) - normalizes to a consistent output format
- writes
INVALIDwhen it can't produce a valid US/Canada 10-digit number
excel/PhoneNumberFormatter.bas
- Open your workbook in Excel.
- Press
Alt + F11to open the VBA editor. - In the VBA editor:
File→Import File...→ chooseexcel/PhoneNumberFormatter.bas. - Run one of these macros:
FormatPhoneNumbersInActiveSheet(active sheet only)FormatPhoneNumbersInWorkbook(all sheets)
Default output is 10 digits (example: 4155550123).
You can change DEFAULT_OUTPUT_STYLE in excel/PhoneNumberFormatter.bas to:
"digits""dash""paren""e164"
Equivalent Google Sheets code lives here:
google-sheets/PhoneNumberFormatter.gs
- Open your Google Sheet.
- Go to
Extensions→Apps Script. - Create a new script file (or replace
Code.gs) and paste in the contents ofgoogle-sheets/PhoneNumberFormatter.gs. - Save.
- Reload the spreadsheet.
- Use the new menu:
Phone Formatter→Format phone numbers (active sheet)orFormat phone numbers (all sheets)
You can also normalize a single cell with:
=NORMALIZE_PHONE_USCA(A2)
Default output is 10 digits.
To change it, set DEFAULT_OUTPUT_STYLE in google-sheets/PhoneNumberFormatter.gs to:
"digits""dash""paren""e164"