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: Sorting ZIP Codes.

Sorting ZIP Codes

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


1

ZIP Codes come in two flavors: five-digit codes and nine-digit codes. If you type a column of ZIP Codes into Excel—some five-digits and some nine—you may wonder why they don't sort correctly.

The reason is that Excel recognizes the five-digit codes as numeric entries, and the nine-digit codes as text entries. (It is the dash in the middle of the nine-digit codes that makes Excel treat the entry as text.) The problem with sorting the numbers is that Excel treats numeric and text values differently when sorting.

The solution (without resorting to formulas and additional columns for sorting) is to make sure that you force Excel to treat all your entries as text. You can do this by formatting a column as text before putting in your first ZIP Code. Simply follow these steps:

  1. Select the column (or cells) you want Excel to treat as text.
  2. Display the Home tab of the ribbon.
  3. Click the small icon at the lower-right corner of the Number group. Excel displays the Format Cells dialog box.
  4. Make sure the Number tab is selected. (See Figure 1.)
  5. Figure 1. The Number tab of the Format Cells dialog box.

  6. In the list of available formats, choose Text.
  7. Click on OK.

This formats the cells as text, and you can then sort the ZIP Codes correctly. Don't be misled here, however: You must make the format change before you enter values in the cells. If you format the cells as Text after you enter information, they still won't sort properly. You can do the following, however:

  1. Format the cells as Text.
  2. Select a cell that has a five-digit ZIP Code in it.
  3. Press F2. This informs Excel you want to edit the cell.
  4. Immediately press Enter. This tells Excel you are done editing the cell.
  5. Repeat steps 2 through 4 for each cell that contains a five-digit ZIP Code.

Once this process is done, you can sort the cells, as desired.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12489) 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: Sorting ZIP Codes.

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

Using a Protected Worksheet

If you have a worksheet protected, it may not be immediately evident that it really is protected. This tip explains some ...

Discover More

Protecting Tracked Changes

Track Changes is a great tool for editors and collaborators to use when creating documents. An author, seeking changes ...

Discover More

Turning Off Track Changes without Unsharing

The Track Changes tool in Excel can be helpful, but it can also be aggravating because it doesn't allow you to use it on ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Sorting a Range of Cells

When you sort data in a worksheet, you don't need to sort everything at once. You can sort just a portion of your data by ...

Discover More

Undoing the Effects of a Sort

Have you ever put a lot of data into a worksheet, sorted that data, and then realized you shouldn't have done so? It is ...

Discover More

Incomplete and Corrupt Sorting

Using the sorting tools, on the toolbar, may result in some unwanted results, such as jumbled data. If this happens to ...

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 2 + 8?

2023-03-25 10:28:56

J. Woolley

Notice the Number tab of the Format Cells dialog includes Special, and Special includes ZIP Code and ZIP Code + 4. This does not solve the sorting issue if there are both types, but it does retain numeric values.


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.