Written by Allen Wyatt (last updated June 9, 2018)
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:
Figure 1. The Number tab of the Format Cells dialog box.
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:
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.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
When creating custom formats, you can employ a wide range of codes to define your formatting pattern. This tip focuses on ...
Discover MoreNeed to hide a given column based on the value in a particular cell? The easiest way to accomplish the task is to use a ...
Discover MoreIf you work with geographic data, you may need a way to display latitude and longitude in a worksheet. This tip examines ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-06-13 20:27:27
Jim Campbell
I would like to add that this works for any that is made up of numbers, i.e. phone numbers, part numbers, serial numbers, etc. This really aren't numbers per se, they are strings of characters which just happen to be numbers.
However, the issue is that you can not (at least in a practical sense), go to each individual cell and hit F2 (to edit) and then enter. Many times, you may be working with tens or even hundreds of thousands of rows.
The answer is one of my all time useful techniques:
1.) Highlight the desired column (You can highlight ONLY one at a time!)
2.) Alt key
3.) A
4.) E
5.) <enter>
6.) <enter>
7.) T
8.) <enter>
This enters the Text-to-Column Wizard to effectively FORMAT the entire column for Text AND act as that needed F2 <enter> combo.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments