Adding Area Codes to Phone Numbers

Written by Allen Wyatt (last updated December 2, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Ron has a worksheet that has a column of phone numbers. Some are seven-digit numbers, as in 123-4567, with the 727 area code assumed. Others have area codes included, as in (890) 123-4567. Ron wants to have every phone number in the latter format and wonders about the best way to detect the shorter phone numbers and add the missing (727) to those numbers.

The best way to go about this is going to depend on the nature of your data. You see, it is possible for the data to be text or numeric. This is possible because Excel provides a special cell format that allows numbers like 8015551212 to be displayed as (801) 555-1212. You can tell whether your data is numeric or text by comparing what you see in the cell with what is shown in the formula bar. (See Figure 1.)

Figure 1. Figuring out if a phone number is text or numeric.

If your data happens to be numeric, you can easily add the proper area code by using a formula such as this:

=IF(A1<=9999999,7270000000+A1, A1)

The result will add the proper area code, but you will still need to format the cell containing this formula with the special Phone Number format.

If the data is textual, then you can simply use a formula to check the length of the cell and then add the area code, as needed:

=IF(LEN(A1) = 8, "(727) " & A1, A1)

Thus, if the phone number is 555-1212 (8 characters long), then this formula returns (727) 555-1212. Of course, it is possible that the phone number may have some extra spaces around it; this often happens if phone numbers are pasted into a worksheet from a different source. In that case, just include the TRIM function in your formula:

=IF(LEN(TRIM(A1)) = 8, "(727) " & TRIM(A1), TRIM(A1))

There's another formula you may find very helpful for adding the area code, and it is shorter than those we've seen so far:

=RIGHT("(727) " & TRIM(A1), 14)

This formula adds the area code to all the cells and then just takes the rightmost 14 characters of the result.

Things become a bit stickier if your data has some phone numbers that are numeric and some that are textual. In that case, you can still put together a formula, but it becomes longer:

=IF(LEN(TRIM(A1)) > 9, TRIM(A1),
IF(LEN(TRIM(A1)) = 8, "(724) " & TRIM(A1),
IF(LEN(TRIM(A1)) = 7, 7240000000+A1, "Undetermined")))

Remember that this is a single formula. It keys off the length of whatever is in cell A1. If the length is over 9 characters, then the phone number is assumed correct. If the length is exactly 8, then the formula assumes it is a "short text" version of the phone number, such as 555-1212, and adds the area code to the beginning. If the length is exactly 7, then it is assumed to be a "short numeric" phone number and the proper number is added to it. If the phone number is not any of these, then the formula returns the text "Undetermined." After using this formula, you'll still need to format the resulting cells using the special Phone Number format.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13564) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Conditional Format that Checks for Data Type

Conditional formatting can be used to highlight cells that contain the improper type of data for your needs. This tip ...

Discover More

Determining Differences Between Dates

Macros are often used to process the data in a worksheet. If that data includes dates that need to be processed, you'll ...

Discover More

Sticking with the Dashes

By default, dashes don't "stick" to the text that follows them. Here's one way around this normal formatting convention.

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

How Operators are Evaluated

Operators are used in formulas to instruct Excel what to do to arrive at a result. Not all operators are evaluated in the ...

Discover More

Segregating Numbers According to Their Sign

Remember your number line from your early years in school? Some numbers can be below zero (negative numbers) and others ...

Discover More

Using a Numeric Portion of a Cell in a Formula

If you have a mixture of numbers and letters in a cell, you may be looking for a way to access and use the numeric ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two less than 9?

2023-12-04 13:09:54

J. Woolley

My Excel Toolbox includes the following function described in detail here: https://excelribbon.tips.net/T011802_Converting_Phone_Numbers.html
    =PhoneTextToDigits(PhoneNumber, [AsNumeric])
PhoneNumber can be either numeric or text. If AsNumeric is TRUE, the result is numeric; otherwise, the result is text. Therefore, Ron's problem can be simplified by adding a helper column with the following formula in cell B1 (TRIM is not necessary):
    =PhoneTextToDigits(A1, TRUE)
If A1 is text like (801) 555-1212, the result is numeric like 8015551212.
Now the Tip's first formula can be applied to the numeric helper column:
    =IF(B1<=9999999, 7270000000+B1, B1)
If your version of Excel includes the LET function, this formula does not require help:
    =LET(N,PhoneTextToDigits(A1,TRUE),IF(N<=9999999,7270000000+N,N))
Numeric phone numbers can be formatted using Special or Custom.
For more on this subject, see https://excelribbon.tips.net/T013383_Adding_an_Area_Code.html
Also, see https://sites.google.com/view/MyExcelToolbox/


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.