COUNTIF and COUNTIFS: How to Count Cells That Match Criteria

COUNTIF counts the cells in one range that meet one condition. COUNTIFS counts rows where every one of several conditions holds across two or more ranges. Most counting problems in a spreadsheet reduce to one of these two functions, and the difficulty is almost never the syntax. It is getting the criteria, the range sizes and the data types right.

This guide sets out how both functions read their inputs, how to choose between them and the alternatives, where they go wrong, and a worked example you can rebuild in a few minutes.

What COUNTIF and COUNTIFS Return

Both functions return a single whole number. They do not return the matching values, and they do not change the source data. If you need the matching rows themselves, you need a filter or a lookup function instead.

COUNTIF syntax

The syntax is:

=COUNTIF(range, criteria)

  • range is the block of cells to test, such as B2:B200.
  • criteria is the condition each cell is tested against, such as "North", ">500" or a cell reference such as F1.

For example, =COUNTIF(B2:B200,"North") returns how many cells in B2 to B200 contain exactly North.

COUNTIFS syntax

The syntax is:

=COUNTIFS(range1, criteria1, range2, criteria2, ...)

You can add up to 127 range and criteria pairs in Excel. Most workbooks use two or three. A row is counted only when every pair is satisfied on that same row. The ranges must all have the same number of rows, which is covered in Module 5.

Tickwell Habit Tracker

Skip the setup

Tickwell Habit Tracker

Tick off habits each day and let the sheet count streaks and monthly completion rates.

See it on Taskdale →

How Criteria Are Read

The criteria argument does most of the work, and it is more flexible than it looks. Understanding how it is interpreted prevents most of the wrong answers people report.

Exact matches, operators and text

A plain value such as "Closed" is an exact match, but the comparison is not case-sensitive. "closed", "CLOSED" and "Closed" all match the same cells.

Operators go inside the quotation marks:

CriteriaMeaningExample result
"Closed"Equals ClosedCounts Closed, closed, CLOSED
"<>Closed"Does not equal ClosedCounts every other value, including blanks
">500"Greater than 500Counts 501 and above
">=500"Greater than or equal to 500Counts 500 and above
"<>"Not blankCounts non-empty cells
"="BlankCounts truly empty cells

To use a value from another cell, join the operator and the reference with an ampersand. For example, ">="&F1 compares against whatever number sits in F1. Leave the operator outside the quotation marks in that case.

Wildcards and literal asterisks

Two wildcard characters work in criteria:

  • * matches any run of characters, including none. "Nor*" matches North and Northwest.
  • ? matches exactly one character. "N?rth" matches North but not Northwest.

If you need to count a cell that contains a real asterisk or question mark, place a tilde in front of it. "~*" counts cells containing an asterisk. Without the tilde, a criteria of "*" counts every non-empty text cell, which is often not what was intended.

Comparing dates and numbers

Dates are stored as serial numbers, so they compare like numbers. Write the criteria with the operator in quotation marks and join the date with an ampersand:

=COUNTIF(E2:E200,">="&DATE(2024,1,1))

Hard-coding a date as text such as ">=01/01/2024" is fragile, because the result depends on the regional setting that reads the text. DATE() avoids that problem.

Choosing Between COUNTIF, COUNTIFS and the Alternatives

Use the simplest function that answers the question. The table below compares the main options for counting cells that match conditions.

FunctionConditions supportedTypical useLimitation
COUNTIFOneCount one status, one region or one thresholdCannot test a second column
COUNTIFSSeveral, all must holdCount status and region together, or a date windowNo native OR logic across different columns
SUM with COUNTIFS and an array of criteriaSeveral, with OR on one columnCount North or East, both ClosedHarder to read; array syntax varies by locale
SUMPRODUCTAny logic, including calculationsConditions that need arithmetic or cell-by-cell mathsSlower on large ranges; no wildcards
COUNTA and COUNTBLANKNon-blank or blank onlyCount filled or empty cellsCannot test values
FILTER with ROWS (Excel 365 and Google Sheets)Any logicCount and also return the matching rowsNeeds dynamic array support
PivotTableAny, set through the interfaceRecurring summaries for reviewDoes not update until refreshed

A practical rule: use COUNTIF for one condition, COUNTIFS for two or more conditions that must all hold, and SUMPRODUCT only when the logic cannot be expressed with comparison operators.

Worked Example

This example uses a small sales log. Rebuild it in a new sheet to check each result against the figures below.

The sample data

Put these headings in row 1 and the data in rows 2 to 9:

RowA: RegionB: RepC: StatusD: AmountE: Close date
2NorthAmaraClosed120014/01/2024
3SouthBenOpen80022/01/2024
4NorthChloeClosed45005/02/2024
5NorthDevOpen210019/02/2024
6EastEliClosed150003/03/2024
7SouthFarahClosed30028/03/2024
8NorthGusClosed98009/04/2024
9EastHanaOpen66017/04/2024

The ranges below use rows 2 to 200 so that new rows added later are picked up. Adjust the end row to suit your data, or convert the block to an Excel table as described in Module 6.

Four counts, step by step

Step 1: count all North deals.
=COUNTIF(A2:A200,"North")
Result: 4 (rows 2, 4, 5 and 8).

Step 2: count North deals that are Closed.
=COUNTIFS(A2:A200,"North",C2:C200,"Closed")
Result: 3 (rows 2, 4 and 8). Row 5 is North but Open, so it is excluded.

Step 3: count Closed deals worth more than 1,000.
=COUNTIFS(C2:C200,"Closed",D2:D200,">1000")
Result: 2 (rows 2 and 6).

Step 4: count Closed deals that closed in Q1 2024.
=COUNTIFS(C2:C200,"Closed",E2:E200,">="&DATE(2024,1,1),E2:E200,"<="&DATE(2024,3,31))
Result: 4 (rows 2, 4, 6 and 7). Row 8 closed in April and is excluded.

Step 5, optional: count North or East deals that are Closed.
=SUM(COUNTIFS(A2:A200,{"North","East"},C2:C200,"Closed"))
Result: 4. The array returns 3 for North and 1 for East (row 6), and SUM adds them. In locales that use commas as decimal separators, the array separator may need to be a semicolon.

Check each result by filtering the sheet on the same conditions. If the filter count and the formula disagree, the cause is almost always a data-type or spacing issue, covered next.

Bellmark Teacher Planner and Gradebook

Ready-made template

Bellmark Teacher Planner and Gradebook

Weighted gradebook, attendance and lesson plans, with grades that calculate as you enter marks.

See it on Taskdale →

Common Mistakes and How to Fix Them

Most reported errors fall into a small set of causes.

Mismatched range sizes

Every range in COUNTIFS must cover the same number of rows. COUNTIFS(A2:A200,"North",C2:C199,"Closed") returns #VALUE! because one range is one row shorter. The fix is to use the same start and end rows for every range. When a formula fails with this error, check the row numbers of each range first.

Numbers stored as text

A value that looks like a number but is stored as text can break a numeric criterion. A count with ">1000" will skip a cell that contains the text "1,200" or a number pasted with a leading apostrophe. Select the column and check the alignment: text usually sits left and numbers sit right. Convert the values with Text to Columns, or with VALUE() in a helper column.

The opposite problem also occurs. COUNTIF treats text that looks like a number as a number. In Excel, =COUNTIF(A:A,"123") counts cells containing 123, the text "123" and the text "0123". This matters for product codes, postcodes and account numbers with leading zeros. For those, add a text-only test or use SUMPRODUCT with EXACT().

Criteria typed as a cell reference without the operator

If F1 contains 500 and you write =COUNTIF(D2:D200,F1), you get an exact match on 500. If you wanted greater than the value in F1, you need =COUNTIF(D2:D200,">"&F1). The ampersand and the operator are both required. Forgetting either one returns a count that looks plausible but answers a different question.

Wildcards that match too much

Typing "North*" also matches “Northwest” and “North Coast”. If you only want the exact region, remove the asterisk. If the criteria comes from a user-typed cell, a stray asterisk can change the count without any error message.

Ranges that do not expand

A fixed range such as A2:A200 ignores row 201 onwards. Users often add rows, see the count stop updating, and assume the formula is wrong. Convert the data to an Excel table and use structured references such as Sales[Region], or use whole-column references such as A:A for COUNTIF and COUNTIFS. Whole columns also include header text, so the header row can match a criterion if it contains the same word.

OR logic written with separate COUNTIFS

Writing =COUNTIFS(A:A,"North",C:C,"Closed")+COUNTIFS(A:A,"East",C:C,"Closed") works, but it is brittle. Adding a third region means editing the formula. The array form in Module 4 scales better. Count each row once, because a row that matches both conditions in an OR test would be counted twice by the separate-formula approach.

Trade-Offs and Edge Cases

Performance on large sheets

COUNTIF and COUNTIFS are fast, and a few hundred formulas over a bounded range rarely slow a workbook. The cost grows when a large number of COUNTIFS formulas each scan whole columns, or when they reference other sheets that recalculate often. Bounded ranges or Excel tables reduce the scan length. If a summary sheet needs thousands of counts over hundreds of thousands of rows, a PivotTable or a single SUMPRODUCT over a helper column may be more efficient. Test before committing to either.

Case sensitivity and whitespace

Both functions ignore case. They do not ignore spaces. "North " with a trailing space is a different value from "North". Data imported from other systems often carries invisible spaces, and the symptom is a count that is lower than the filter count. The TRIM() function in a helper column, or a data-cleaning step on import, removes them.

If you need case-sensitive counting, COUNTIF cannot do it. Use SUMPRODUCT(--EXACT(A2:A200,"North")) instead.

Criteria length and cross-sheet references

Excel limits a criteria string to 255 characters. Long text criteria, such as a pasted sentence, can trigger errors or silent mismatches. Shorter criteria stored in a cell avoid the problem.

COUNTIF and COUNTIFS accept ranges on other sheets, so =COUNTIF(Sales!A2:A200,"North") works from any sheet. Keep the sheet name in single quotation marks if it contains a space, such as 'Q1 Sales'!A2:A200.

Google Sheets differences

COUNTIF and COUNTIFS work the same way in Google Sheets for everyday use. Wildcard behaviour is broadly the same, but regular expressions are available through separate functions such as REGEXMATCH inside a SUMPRODUCT or ARRAYFORMULA. If a workbook moves between Excel and Sheets, test the wildcard and tilde cases separately, because the edge behaviour is where the two products diverge.

Blank cells and the empty string

COUNTIF(range,"") counts both truly empty cells and cells holding an empty string, such as a formula that returns "". COUNTIF(range,"=") counts only truly empty cells. The distinction matters when a column contains formulas that return blanks, because the two formulas can disagree. Use COUNTBLANK when you want the first behaviour and check which definition your report needs.

Decision Checklist

Use this sequence when you need a count.

  1. Write the question in plain words, such as “How many Closed deals were worth more than 1,000?”
  2. List each condition and the column it lives in. One condition points to COUNTIF. Two or more that must all hold point to COUNTIFS.
  3. Check that each range covers the same rows, and that they all start and end at the same row numbers.
  4. Confirm the data types. Numbers should sit right-aligned, dates should be real dates, and codes with leading zeros should be checked for text or number storage.
  5. For operators and cell references, join the operator and the reference with an ampersand, and keep the operator inside the quotation marks.
  6. For OR logic across one column, use the SUM and array form. For logic that needs arithmetic, use SUMPRODUCT.
  7. Test the result against a filter on the same conditions. Investigate any difference before the formula is copied into a report.
  8. If the data will grow, convert it to an Excel table or use a whole-column reference, and record the choice in the workbook notes so that the next person knows why it was made.

If a count matters to a decision, keep the test filter in the workbook beside the formula. A count that cannot be reproduced by hand is harder to trust, and a mismatch found early costs far less than one found in a finished report.

Landfall Job Application Tracker

Get the finished file

Landfall Job Application Tracker

Track every application, interview and follow-up date, with drop-downs for status.

See it on Taskdale →

Scroll to Top