Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Sorting ZIP Codes.

Sorting ZIP Codes

Written by Allen Wyatt (last updated December 23, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003


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. Choose the Cells option from the Format menu. Excel displays the Format Cells dialog box.
  3. Make sure the Number tab is selected. (See Figure 1.)
  4. Figure 1. The Number tab of the Format Cells dialog box.

  5. In the list of available formats, choose Text.
  6. 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 (2793) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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 Revision Tracking

Want to keep track of the changes other people make to your workbook or even your own changes? Excel makes gathering this ...

Discover More

Auto-incrementing Form Fields

Templates are a great way to create new documents because they act as intricate patterns to what those new documents ...

Discover More

Leaving Trace Precedents Turned On

The Trace Precedents auditing tool can be quite helpful in seeing which cells "feed into" a particular formula. The ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Removing All Formatting

Getting rid of formatting from a cell or group of cells can be done using several different techniques. This tip ...

Discover More

Formatting Combo Box Text

If you insert objects, such as a combo box, in your worksheet, you may need a way to modify the font used in the object. ...

Discover More

Altering the Displayed Format of Numbers to the Nearest 100

Want information in a worksheet to be formatted and displayed as rounded to a power of ten? You may be out of luck, ...

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 nine minus 5?

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 menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.