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

Deleting Tab Stops

Need to delete some tabs tops in a paragraph? It's easy to do using the Tabs dialog box, as described in this tip.

Discover More

Turning Off AutoFill

AutoFill is a great editing tool that comes in particularly handy when you are first creating a worksheet. You may, at ...

Discover More

Changing Elements in Lots of Charts at One Time

Got a bunch of charts that you need to make formatting changes in? You can use a macro (or two) to apply the formatting ...

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 (menu)

Adding Drop Shadows to Cells

Want to draw attention to what is in a cell? What better way than to add a drop shadow to that cell! Here's how you can ...

Discover More

Hiding Rows Based on a Cell Value

This tip contains a macro to hide rows that contain data you don't want to see.

Discover More

Preventing Changes to Formatting and Page Size

When you create workbooks for others to use, you might want to make sure that they can't change the formatting and paper ...

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.