COUNTIF Conditional Formatting: How to Use It

Formulas & functions · Updated November 23, 2026

To apply conditional formatting with COUNTIF, select your data range, go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, enter a formula like =COUNTIF($A$2:$A$20, A2)>1, and set a format. This highlights duplicate values or cells that meet a count-based condition. Below, you’ll find the full mechanics, examples, and troubleshooting.

What COUNTIF Does in Conditional Formatting

COUNTIF is a function that counts cells in a range that meet a single condition. Its syntax is =COUNTIF(range, criteria). When used inside a conditional formatting rule, it returns a number, and the rule triggers if that number evaluates to TRUE (any non-zero number). This lets you format cells based on how often a value appears, or based on counts of related data.

For example, to highlight all cells in column A that appear more than once, you’d use =COUNTIF($A$2:$A$20, A2)>1 applied to A2:A20. The dollar signs lock the range so the formula adjusts for each row.

How to Set Up a COUNTIF Conditional Formatting Rule

Here are the exact steps for Excel for Microsoft 365 on Windows:

  1. Select the range you want to format (e.g., A2:A20).
  2. Go to Home > Conditional Formatting > New Rule.
  3. Choose Use a formula to determine which cells to format.
  4. In the formula box, type your COUNTIF formula. For duplicates: =COUNTIF($A$2:$A$20, A2)>1.
  5. Click Format, pick a fill or font color, and click OK.
  6. Click OK again to apply.

On Mac, the path is the same: Home tab > Conditional Formatting > New Rule. The formula syntax is identical.

Practical Examples of COUNTIF Rules

Here are three common scenarios with the exact formulas and expected results.

  • Highlight duplicates in a list: With data in A2:A20, use =COUNTIF($A$2:$A$20, A2)>1. Every cell whose value appears more than once gets highlighted.
  • Highlight entire rows based on a count: If you have order IDs in column A and want to highlight rows where an ID appears more than 3 times, select A2:D20 (the full table), and use =COUNTIF($A$2:$A$20, $A2)>3. The formula uses a mixed reference ($A2) so it evaluates per row.
  • Highlight cells that appear exactly once: Use =COUNTIF($A$2:$A$20, A2)=1 to highlight unique values.

For the first example, if A2:A20 contains “Apple”, “Banana”, “Apple”, “Cherry”, then the cells with “Apple” will be highlighted because the count is 2.

Choosing the Right Range and References

The key to a working COUNTIF rule is understanding relative vs absolute references. When you apply a rule to a range, Excel evaluates the formula for the top-left cell first, then adjusts references relative to that cell.

  • Use absolute references (e.g., $A$2:$A$20) for the range you are counting – this keeps the range fixed.
  • Use relative references (e.g., A2) for the criteria – this changes as the rule moves down the range.
  • For row highlighting, use a mixed reference like $A2 to keep the column fixed but allow the row to change.

If you accidentally use =COUNTIF(A2:A20, A2)>1 without dollar signs, the range will shift for each row, giving incorrect results.

Common Problems and How to Fix Them

Several issues arise frequently when using COUNTIF in conditional formatting.

  • Rule applies to wrong cells: Ensure the “Applies to” range in the rule manager matches your selection. If you change the selection after creating the rule, update it manually.
  • Formula returns #NAME?: This usually means a typo in the function name. Check that it says COUNTIF, not COUNT IF.
  • Text with leading/trailing spaces: COUNTIF treats “Apple” and “Apple ” as different. Use =SUMPRODUCT(--(TRIM($A$2:$A$20)=TRIM(A2)))>1 to ignore spaces, but that’s not a COUNTIF formula.
  • Case sensitivity: COUNTIF is not case-sensitive. If you need case-sensitive duplicates, use =SUMPRODUCT(--(EXACT($A$2:$A$20, A2)))>1.
  • Rule not updating: If you edit data, the formatting updates automatically, but if you change the range, you must edit the rule’s formula.

Comparing COUNTIF with Other Methods

For highlighting duplicates, you might also use the built-in Highlight Cells Rules > Duplicate Values. That tool is simpler but less flexible: it only highlights duplicates (count > 1), not counts greater than a specific number, and it cannot highlight entire rows.

COUNTIF is more powerful because you can use any comparison operator (>1, =3, etc.) and combine it with other functions. For example, to highlight cells that appear more than twice and are in a specific category, you could use =AND(COUNTIF($A$2:$A$20, A2)>2, B2="Yes").

Performance and Large Data Sets

COUNTIF is fast for moderate-sized ranges (up to tens of thousands of rows), but on very large datasets (100,000+ rows), it can slow down because each cell recalculates the count over the entire range. For better performance, consider using a helper column with =COUNTIF(A:A, A2) and then apply a simple conditional formatting rule based on that column’s value (e.g., =$C2>1). This calculates the count once per row instead of once per cell.

Frequently Asked Questions

Can I use COUNTIF with wildcards in conditional formatting?

Yes. For example, to highlight cells that contain “apple” as part of the text, use =COUNTIF($A$2:$A$20, "*apple*")>0. The asterisks are wildcards. Note that this counts cells containing “apple”, not cells equal to “apple”.

Why is my COUNTIF conditional formatting highlighting blank cells?

COUNTIF counts blank cells if the criteria is an empty string. If your range includes blanks, use =AND(A2<>"", COUNTIF($A$2:$A$20, A2)>1) to exclude blanks.

How do I highlight a whole row based on a count in another column?

Select the entire table range (e.g., A2:D20), create a new rule with formula =COUNTIF($A$2:$A$20, $A2)>1. The mixed reference $A2 locks the column but allows the row to change, so each row is evaluated based on its own column A value.

Does COUNTIF work with dates or numbers in conditional formatting?

Yes. For example, to highlight dates that appear more than once, use =COUNTIF($A$2:$A$20, A2)>1. Dates are stored as numbers, so the comparison works normally.

Can I use COUNTIFS (multiple criteria) in conditional formatting?

Absolutely. For instance, to highlight rows where the same product (column A) appears more than once and the region (column B) is “West”, use =AND(COUNTIFS($A$2:$A$20, $A2, $B$2:$B$20, "West")>1, $B2="West"). COUNTIFS works the same way but accepts multiple range/criteria pairs.

Alternatives to COUNTIF for Conditional Formatting

If you need to highlight based on counts but COUNTIF feels limiting, consider these:

  • COUNTIFS for multiple conditions (as above).
  • SUMPRODUCT for case-sensitive or trimmed-text comparisons.
  • Helper columns with a simple formula like =COUNTIF(A:A, A2) – then use a basic rule like =$C2>1.
  • Power Query to transform data before applying formatting, but that’s for more complex scenarios.

Remember that conditional formatting rules are recalculated whenever the workbook recalculates. If you have many rules, performance can degrade; use helper columns for large datasets.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

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

Spotted an error in this guide? Let us know.