The short answer: Excel’s COUNTIF function only accepts one criteria range and one condition, so you cannot pass multiple arguments directly to a single COUNTIF. To count cells that meet multiple conditions, use COUNTIFS, which is designed for up to 127 range/criteria pairs, or use COUNTIF with array constants for certain cases.
What COUNTIF Does and Its Limitation
COUNTIF is one of Excel’s oldest counting functions. Its syntax is COUNTIF(range, criteria), where range is the group of cells you want to examine and criteria is the condition that determines which cells to count. For example, =COUNTIF(A2:A20,"Apple") counts how many times “Apple” appears in cells A2 through A20.
The function is intentionally simple. It handles a single condition on a single range. If you try to add a second argument, Excel returns an error like #VALUE! or simply ignores the extra input. This limitation is why Microsoft introduced COUNTIFS in Excel 2007—it extends the same idea to multiple conditions.
Using COUNTIFS for Multiple Conditions
COUNTIFS has the syntax COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...). Each range must have the same number of rows and columns, but they can be different columns or even different sheets. The function counts a row only if all conditions are true for that row.
Example: Suppose column A lists product names (A2:A20) and column B lists sales regions (B2:B20). To count rows where the product is “Apple” and the region is “North”, use:
=COUNTIFS(A2:A20,"Apple",B2:B20,"North")
If the data has 3 rows with Apple/North, the formula returns 3.
You can add more pairs: =COUNTIFS(A2:A20,"Apple",B2:B20,"North",C2:C20,">100") counts rows where product is Apple, region is North, and sales in column C exceed 100.
Criteria can be numbers, text, expressions, or cell references. For example, =COUNTIFS(B2:B20,">="&D1) uses the value in cell D1 as the threshold.
Alternative: COUNTIF with Array Constants
For a single range and multiple criteria that are alternatives (OR logic), you can use an array constant inside COUNTIF. For instance, to count cells in A2:A20 that are either “Apple” or “Orange”:
=SUM(COUNTIF(A2:A20,{"Apple","Orange"}))
This works because COUNTIF returns an array of two counts (one for each criteria), and SUM adds them. In older Excel versions, you must press Ctrl+Shift+Enter to enter it as an array formula, but in Excel 365 and Excel 2021 it works normally due to dynamic arrays.
Be careful: this counts cells that match either criteria, so a cell containing “Apple” is counted once, not twice. If you need to count cells that match all of several criteria on the same range, COUNTIFS is the correct tool, not this array trick.
How to Choose Between COUNTIF and COUNTIFS
Use COUNTIF when you have exactly one condition. Use COUNTIFS when you have two or more conditions that must all be true (AND logic). For OR logic across multiple conditions, you have several options:
- Use
SUM(COUNTIF(range,{crit1,crit2}))for a small set of alternatives. - Add multiple COUNTIF results together, e.g.,
=COUNTIF(A2:A20,"Apple")+COUNTIF(A2:A20,"Orange"). - Use SUMPRODUCT for more complex logic, e.g.,
=SUMPRODUCT(((A2:A20="Apple")+(A2:A20="Orange"))>0).
For counting with multiple criteria on different columns, COUNTIFS is almost always the cleanest and fastest solution.
Common Problems and Errors
Several issues arise when working with multiple criteria:
- #VALUE! error: Occurs when ranges in COUNTIFS are not the same size. Ensure each criteria_range has the same number of rows and columns.
- Criteria with wildcards: COUNTIF and COUNTIFS support wildcards: * (any sequence), ? (single character), and ~ (escape). For example,
=COUNTIF(A2:A20,"A*")counts cells starting with “A”. - Blank cells: To count blanks, use
""as criteria; to count non-blanks, use"<>". - Case sensitivity: Both functions are case-insensitive. For case-sensitive counting, use SUMPRODUCT with EXACT.
- Criteria with comparison operators: When using >, <, >=, <=, or <>, enclose the operator in quotes and concatenate with a cell reference if needed, e.g.,
">="&D1.
Comparison with Other Counting Functions
Excel offers several counting functions, each suited to different scenarios:
- COUNT: Counts numeric cells.
- COUNTA: Counts non-empty cells.
- COUNTBLANK: Counts empty cells.
- COUNTIF: Counts cells meeting one condition.
- COUNTIFS: Counts cells meeting multiple conditions (AND logic).
- SUMPRODUCT: A versatile function that can count with complex logic, including OR and case-sensitive conditions.
For example, to count cells in A2:A20 that are either “Apple” or “Orange” and also have a value in B2:B20 greater than 10, you could use SUMPRODUCT with multiplication: =SUMPRODUCT(((A2:A20="Apple")+(A2:A20="Orange"))*(B2:B20>10)). This is more flexible but can be slower on large datasets.
Performance and Best Practices
COUNTIFS is generally fast, but with very large datasets (hundreds of thousands of rows) it can slow down. To improve performance:
- Limit the range to the actual data area, not entire columns (e.g., A2:A100000 instead of A:A).
- Avoid using entire column references like A:A if possible.
- Use Excel Tables (Insert > Table) so ranges automatically adjust and stay compact.
- For extremely large data, consider using a PivotTable or Power Query instead of multiple COUNTIFS formulas.
Also, remember that COUNTIFS ignores cells with text that cannot be interpreted as numbers when using numeric criteria. For example, =COUNTIFS(A2:A20,">10") will not count cells containing text like “ten”.
Frequently Asked Questions
Can I use COUNTIF with two criteria ranges?
No, COUNTIF only accepts one range and one criteria. For two or more ranges, use COUNTIFS. The syntax is COUNTIFS(range1, criteria1, range2, criteria2).
How do I count cells that meet any of several conditions (OR logic)?
Use =SUM(COUNTIF(range,{crit1,crit2})) for a single range, or add multiple COUNTIF results. For multiple ranges with OR logic, use SUMPRODUCT with addition, e.g., =SUMPRODUCT((A2:A20="Apple")+(B2:B20="Orange")).
Why does my COUNTIFS return 0 even though I see matches?
Check that the criteria ranges are the same size and that the criteria are typed correctly. Also ensure you are not using wildcards unintentionally—for example, “*” matches any text, so if you want a literal asterisk, use “~*”.
Is COUNTIFS case-sensitive?
No, COUNTIFS is not case-sensitive. For case-sensitive counting, use SUMPRODUCT with EXACT, like =SUMPRODUCT(--EXACT(A2:A20,"Apple")).
Can I use COUNTIFS across different sheets?
Yes, you can reference ranges on different sheets in the same workbook. For example, =COUNTIFS(Sheet1!A2:A20,"Apple",Sheet2!B2:B20,"North") works as long as the ranges are the same size.
Related
- How to Update R Version (Windows, Mac, Linux)
- Modify Windows Shortcuts: Full Guide to Remapping Keys
- Traffic Light Time Duration: How Long Each Light Lasts
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Percent Change Formula and ExamplesTo calculate percent change in Excel, subtract the old value from the new value, then divide by the…
- Excel Formula for Checkbook Ledger: Setup & ExamplesThe core Excel formula for a checkbook ledger is a running balance: =SUM($C$2:C2) entered in the balance column,…
- Arduino Pass String to Function: Examples, Types, and SafetyYes. In Arduino C++, pass a String to a function by putting its type in the parameter list,…
- Extract Day from Date in Excel: Formula and StepsTo extract the day of the month from an Excel date, put the date in A2 and enter…
- Excel IF ISNUMBER: Check Whether a Cell Contains a NumberTo make Excel return one result when a cell contains a number and another when it does not,…
- Excel Flash Fill: Fill a Column Without a FormulaExcel Flash Fill is not a formula: it recognizes a pattern in examples you type and fills the…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.