How to Highlight Zip Codes in Excel

How-to basics · Updated November 23, 2026

To highlight zip codes in Excel, use conditional formatting with a rule that targets cells containing text matching a zip code pattern (e.g., 5 digits, ZIP+4, or a specific list). For a quick start, select your data range, go to Home > Conditional Formatting > New Rule, choose “Use a formula to determine which cells to format,” enter a formula like =ISNUMBER(SEARCH("12345",A1)) to highlight a specific code, or =AND(ISNUMBER(A1),LEN(A1)=5) to highlight all 5-digit numeric codes, then set a fill color.

Why Highlight Zip Codes?

Zip codes are often stored as numbers or text, and they can be tricky to work with because leading zeros (e.g., 01234) get lost if the column is numeric. Highlighting them helps you quickly spot missing, invalid, or duplicate entries, or focus on a specific geographic area for analysis—like a marketing campaign or delivery route. Conditional formatting is the built-in Excel tool for this, and it updates automatically when data changes, so you don’t have to reapply formatting manually.

Understanding Zip Code Formats

Before you write any formula, know that zip codes can appear in several formats:

  • 5-digit (e.g., 90210)
  • ZIP+4 (e.g., 90210-1234)
  • Leading zeros (e.g., 01234) – these are text in Excel, because numbers drop leading zeros.
  • As text with spaces or dashes (e.g., “90210 1234”)

If your data came from a database or import, zip codes might be stored as numbers, which can cause problems. To avoid issues, consider storing zip codes as text (format the column as Text before entering data). For highlighting, you’ll need to account for these variations in your formula.

Method 1: Highlight Specific Zip Codes (Using a List)

Suppose you have a list of target zip codes in cells D2:D5 (e.g., 10001, 10002, 10003, 10004) and your data in A2:A100. To highlight rows where the zip code in column A matches any in that list, use the COUNTIF function.

Select A2:A100, go to Home > Conditional Formatting > New Rule > Use a formula, and enter:

=COUNTIF($D$2:$D$5,$A2)>0

Click Format, choose a fill color, and click OK. This works even if your zip codes are stored as text or numbers, as long as they match exactly. If you have ZIP+4 codes and only want to match the first 5 digits, use =COUNTIF($D$2:$D$5,LEFT($A2,5))>0.

Method 2: Highlight All Valid 5-Digit Zip Codes

To highlight every cell that contains a valid 5-digit U.S. zip code (assuming no ZIP+4), you can use a formula that checks if the cell is exactly 5 characters long and consists of digits. With data in A2:A100, select the range and create a new rule with this formula:

=AND(ISNUMBER(A2),LEN(TEXT(A2,"00000"))=5)

This converts the number to text with leading zeros, then checks length. However, if your zip codes are stored as text (e.g., “01234”), use:

=AND(LEN(A2)=5,ISNUMBER(--A2))

The double unary -- converts text to a number; if it’s not numeric, it returns an error, so ISNUMBER will be FALSE. This highlights only 5-digit numeric text. For ZIP+4, use =AND(LEN(A2)=10,MID(A2,6,1)="-",ISNUMBER(--LEFT(A2,5)),ISNUMBER(--RIGHT(A2,4))).

Method 3: Highlight Duplicate Zip Codes

If you need to find duplicate zip codes, you can use a conditional formatting rule based on COUNTIF. Select your range (e.g., A2:A100), go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values—this works for any data, but it treats numbers and text differently, so “01234” and 1234 won’t match. For a more robust duplicate check that treats leading zeros correctly, use a formula rule:

=COUNTIF($A$2:$A$100,A2)>1

This highlights all cells that appear more than once. To highlight only the second and later occurrences (not the first), use =COUNTIF($A$2:A2,A2)>1—this counts up to the current row, so the first occurrence is not highlighted.

How to Apply Highlighting to Entire Rows

Often you want to highlight the entire row based on a zip code in a specific column (say column B). Select the range from A2 to C100 (or whatever your table is), and create a new rule with a formula that references the zip code column with a mixed reference (lock the column, not the row). For example, if zip codes are in B2:B100, select A2:C100 and use:

=$B2="90210"

The dollar sign before B locks the column, so the rule applies to all columns in the selected range, but the row changes relative to each row. This is a common technique for row-level highlighting.

Common Problems and Solutions

Here are typical issues you might run into:

  • Leading zeros disappear: If you type 01234, Excel converts it to 1234. To prevent this, format the column as Text before entering data, or use a custom number format 00000 (but that only displays zeros, doesn’t store them). For conditional formatting, if your data is numeric, use =TEXT(A2,"00000")="01234" to match.
  • Zip codes stored as numbers with decimals: Sometimes imported data has 90210.0. Use =ROUND(A2,0)=90210 to handle that.
  • Case sensitivity: Not an issue for numbers, but if you have letters (e.g., Canadian postal codes), use UPPER or LOWER functions.
  • Rule not applying to new data: Conditional formatting only applies to the range you selected. If you add rows below, the rule won’t cover them. Use a table (Insert > Table) so formatting auto-extends.

Using Excel Tables for Dynamic Highlighting

If you convert your data range to an Excel Table (select data, press Ctrl+T), conditional formatting rules will automatically apply to new rows added to the table. This is a best practice for any dynamic dataset. To do this, select your data, press Ctrl+T (on Mac: Cmd+T), ensure “My table has headers” is checked, then apply your conditional formatting rule to the table column (e.g., Table1[Zip]). The rule will use structured references like =[@Zip]="90210"—Excel handles the syntax for you.

Frequently Asked Questions

Q: How do I highlight zip codes that are not in a specific list?
Use the COUNTIF method but change the condition to =COUNTIF($D$2:$D$5,$A2)=0. This highlights cells that are not in the list.

Q: Can I highlight based on the first 3 digits of a zip code?
Yes. Use =LEFT(A2,3)="902" to highlight all zip codes starting with 902. This works whether the cell is text or a number—but if it’s a number, LEFT will convert it to text, so it’s safe.

Q: Why doesn’t my formula work when the zip code is a number?
If the cell contains a number, functions like LEN or LEFT treat it as text automatically, but comparisons like =A2="90210" will fail because 90210 (number) is not equal to “90210” (text). Use =TEXT(A2,"00000")="90210" or convert your data to text first.

Q: How do I remove highlighting later?
Select the range, go to Home > Conditional Formatting > Clear Rules > Clear Rules from Selected Cells. This removes all rules from that range.

Q: Does this work in Google Sheets?
Yes, the same concepts apply, but the menu is Format > Conditional formatting, and you use custom formulas like =COUNTIF($D$2:$D$5,$A2)>0. The syntax is nearly identical.

Final Tips for Working with Zip Codes

Always consider whether your zip codes are text or numbers. To avoid data entry errors, format the column as Text before typing. If you’re importing data, use the Text Import Wizard to specify the column as Text. For analysis, you might also want to extract the first 5 digits with =LEFT(A2,5) if you have ZIP+4. Remember that conditional formatting is a visual aid—it doesn’t change the data itself. If you need to filter or sort, use Excel’s built-in filtering or the FILTER function (Excel 2021 or Microsoft 365).

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.