Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Determining a State from an Area Code.

Determining a State from an Area Code

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


Steve has phone numbers in column A, such as 3035551212, and would like to be able to look at the first three digits (the area code) and return in column B, the state with which that area code is associated. He wonders about the best way to accomplish this.

Excel has many functions that make life easier when you are trying to manipulate data. In this case, using the VLOOKUP function to match the area code to the corresponding state is simple.

Before applying a function to retrieve the information you want, you need to create a simple data table that contains the data you want retrieved. In this table, you need to have the area codes and states in their own columns side-by-side, within your worksheet, sorted by area code. For instance, you might put the area codes in column F and the states for those area codes in column G. The area codes and states can be found on a number of websites, or you can create your own table if you prefer.

Once you've got the data into the two columns, select those columns and create a name for the selected range. (How you create a named range has been covered in other issues of ExcelTips.) For example, you might name the range something like StateCodes. This naming, while not strictly necessary, makes using the lookup formula easier.

Assuming that the phone number is in cell A1 and that you would like the state name returned in the column next to the phone number, in cell B1 you would enter:

=VLOOKUP(VALUE(LEFT(A1,3)),StateCodes,2,FALSE)

The VALUE and LEFT functions are used to pull just the first three characters from the phone number. This is then used in the VLOOKUP formula to find the area code in the StateCodes table. Excel returns the name of the state that corresponds with the area code.

Another way that you can pull out the area code (which is essential for the lookup) is to use the FLOOR function, as shown here:

=VLOOKUP(FLOOR(A1/10000000,1),StateCodes,2,FALSE)

Note that this approach requires that the phone number be stored as a number, so it can be divided by 10,000,000.

The approaches discussed here work great, provided that your phone numbers are always in the specified format (3035551212). If your phone numbers have a different format—perhaps one that uses parentheses and dashes—then the formula won't work and will need to be adjusted to look at where the area code really is in the phone number. If you have phone numbers that are not in a single format, then all bets are off and the task of doing the lookup becomes much, much harder.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8065) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Determining a State from an Area Code.

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

Quickly Moving Your Table

For those who love to use the mouse during editing, you can use the little critter to help move your tables to exactly ...

Discover More

Adjusting Space Before

If you need to adjust the space that appears before a paragraph, there are several ways you can approach the adjustment. ...

Discover More

Deleting Styles

As documents evolve, so do your needs for various styles. You may create new ones and, invariably, old ones need to be ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Summing Only Positive Values

If you have a series of values and you want to get a total of just the values that meet a specific criteria, then you ...

Discover More

Generating a Gift Exchange List

Want to figure out how to do a gift exchange for your family or office? There are a variety of ways you can approach the ...

Discover More

Finding the Address of the Lowest Value in a Range

Uncovering the lowest value in a range is relatively easy; you can just use the MIN worksheet function. Discovering the ...

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 seven more than 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.