Written by Allen Wyatt (last updated January 25, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
In the United States, ZIP Codes come in two formats: five-digit and nine-digit. (Actually, the five-digit ZIP Code is a subset of the nine-digit ZIP Code.) If you are in an Excel worksheet that contains address information, you may want to convert nine-digit ZIP Codes to their five-digit equivalent.
This is a rather easy task to accomplish, since all you need to do is strip everything after the fifth digit in the ZIP Code. Follow these steps:
=Left(G3, 5)
Figure 1. The Paste Special dialog box.
If you have an empty column to the right of your ZIP Codes, you can also use Excel's Text to Columns feature:
Figure 2. The first step of the Convert Text to Columns Wizard.
At this point you have the first five digits of the ZIP Code in the original column and the last four digits (if any) in the previously empty column to the right. You can delete the column containing the four digits, if desired.
If you need to truncate ZIP Codes quite often, you may be more interested in a macro-based approach. The following macro will do the trick:
Sub ZIPShorter() For Each cell In Selection cell.Value = Left(cell.Value, 5) Next End Sub
All you need to do is select the cells containing the ZIP Codes, and then run the macro.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10768) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Shortening ZIP Codes.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Got a large group of people listed in a worksheet and you want to make sure that each person has met with every other ...
Discover MoreOne of the staples of high school algebra classes is the quadratic equation. If you need to solve such equations in ...
Discover MoreIf you have a list of names in a column, and you want to separate those names into individual cells, there are several ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-10-02 12:12:37
Surey Rios
This worked like a charm! Thanks!
2021-08-08 12:21:12
Willy Vanhaelen
@J. Woolley
I just found out that your version works in Excel 2019 but not in 2007. My version works in both.
2020-01-27 10:28:40
J. Woolley
@Willy Vanhaelen
Here's a simpler version of your one-liner:
Sub ZIPShorter()
Selection = Evaluate("LEFT(" & Selection.Address & ",5)")
End Sub
2020-01-25 12:07:53
Willy Vanhaelen
You can replace this macro with a one-liner:
Sub ZIPShorter()
Selection = Evaluate("IF({1},LEFT(" & Selection.Address & ",5))")
End Sub
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.
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