COUNTIF with Range: How to Use It in Excel

Formulas & functions · Updated November 22, 2026

The direct answer: COUNTIF(range, criteria) counts cells within a single range that meet one condition, for example =COUNTIF(A2:A100, "Paid"). To count with multiple ranges or multiple conditions, you need COUNTIFS (for multiple criteria) or a different approach like SUMPRODUCT.

What COUNTIF Actually Does

COUNTIF is a statistical function in Excel that counts the number of cells in a specified range that satisfy a single condition. The function takes exactly two arguments:

  • range – the group of cells you want to evaluate (e.g., A2:A100).
  • criteria – the condition that determines which cells to count. This can be a number, text, expression, or cell reference.

For example, with sales amounts in B2:B20, =COUNTIF(B2:B20, ">100") returns the number of sales over 100. If the result is 7, that means seven cells in that range contain a value greater than 100.

How to Write the Criteria Correctly

The criteria argument is the most common source of errors. It must be enclosed in double quotes when it is a text string, a logical expression, or a wildcard. Numbers can be used directly without quotes, but mixing them with operators requires quotes.

  • Text exact match: =COUNTIF(A2:A20, "Apples")
  • Number exact match: =COUNTIF(B2:B20, 50)
  • Greater than a number: =COUNTIF(B2:B20, ">50")
  • Cell reference in criteria: =COUNTIF(B2:B20, ">"&C1)
  • Wildcard for text containing “apple”: =COUNTIF(A2:A20, "*apple*")

Note that when using a cell reference, you concatenate the operator with the reference using the ampersand (&). Writing ">C1" would be treated as the literal text “>C1” and return 0.

COUNTIF vs. COUNTIFS: When You Need More Than One Range

Many users mistakenly try to use COUNTIF with multiple ranges, like =COUNTIF(A2:A10, B2:B10, "Yes"), which returns a #VALUE! error. The correct function for multiple criteria is COUNTIFS, which accepts pairs of range and criteria:

=COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)

For example, to count rows where region (A2:A100) is “West” and sales (B2:B100) are greater than 5000, use:

=COUNTIFS(A2:A100, "West", B2:B100, ">5000")

COUNTIFS also works with a single range and single criteria, so it can replace COUNTIF entirely, but COUNTIF is simpler when you only have one condition.

Common Problems and How to Fix Them

Several issues trip up users regularly:

  • #VALUE! error – Usually means the range and criteria are not compatible, or you used multiple ranges without COUNTIFS.
  • Counting blank or non-blank cells – Use =COUNTIF(A2:A100, "") to count blanks, and =COUNTIF(A2:A100, "<>") to count non-blanks. Note that "<>" counts cells that contain any character, including spaces, and also counts cells with formulas that return an empty string.
  • Case sensitivity – COUNTIF is not case-sensitive. “apple” and “APPLE” are treated the same. If you need case-sensitive counting, use SUMPRODUCT(--EXACT(range, "apple")).
  • Leading/trailing spaces – If your data has extra spaces, COUNTIF may not match. Use TRIM on the data or include the space in the criteria like " apple".
  • Counting with dates – Dates are stored as numbers in Excel. To count dates after a certain date, use =COUNTIF(A2:A100, ">"&DATE(2024,1,1)) or reference a cell containing a date.

Using Wildcards for Partial Matches

Wildcards let you count cells that contain a specific text pattern. Excel supports three wildcards:

  • * (asterisk) – matches any sequence of characters. "*east" matches “Northeast” and “Southeast”.
  • ? (question mark) – matches any single character. "A?B" matches “A1B” and “A-B”.
  • ~ (tilde) – escapes the next character, so you can match a literal asterisk or question mark. "*~?*" matches any text that contains a question mark.

For example, to count all cells in A2:A20 that contain the word “apple” anywhere, use =COUNTIF(A2:A20, "*apple*"). To count cells that start with “A”, use "A*".

Alternatives for Complex Counting

When COUNTIF and COUNTIFS are not enough, consider these alternatives:

  • SUMPRODUCT – Can handle arrays, case-sensitive matching, and multiple conditions across ranges of different sizes. Example: =SUMPRODUCT((A2:A100="West")*(B2:B100>5000)) counts rows meeting both conditions.
  • FILTER – In Excel 365, =ROWS(FILTER(A2:B100, (A2:A100="West")*(B2:B100>5000))) returns the count of matching rows.
  • COUNTBLANK – Counts empty cells in a range, simpler than COUNTIF for that purpose.
  • COUNTUNIQUE – Not an Excel function, but in Google Sheets, COUNTUNIQUE counts distinct values. In Excel, use =SUMPRODUCT((COUNTIF(A2:A20,A2:A20)>0)/COUNTIF(A2:A20,A2:A20)) or the newer =ROWS(UNIQUE(A2:A20)) in Excel 365.

Frequently Asked Questions

Can I use COUNTIF with two separate ranges? No, COUNTIF accepts only one range. Use COUNTIFS for multiple ranges, or SUMPRODUCT if you need to compare different-sized ranges.

Why does COUNTIF return 0 when I see matching text? Check for extra spaces, non-printing characters, or that the text is not actually a number stored as text. Use =TRIM(A2) to clean data, or use wildcards like "*"&D1&"*".

How do I count cells that contain a number greater than 10 but less than 20? Use COUNTIFS: =COUNTIFS(A2:A100, ">10", A2:A100, "<20"). COUNTIF cannot handle two conditions on the same range.

Is COUNTIF case-sensitive? No, it is not. For case-sensitive counting, use =SUMPRODUCT(--EXACT(A2:A100, "Apple")).

Can I use a cell reference for the criteria without quotes? Yes, but only if the cell contains the exact value. For example, =COUNTIF(A2:A100, C1) counts cells equal to whatever is in C1. If you need an operator, you must concatenate: =COUNTIF(A2:A100, ">"&C1).

What does #NAME? error mean? It usually means you misspelled the function name (e.g., “COUNTIFS” vs “COUNTIF”) or you are using a function not available in your Excel version. COUNTIFS is available in Excel 2007 and later.

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.