Excel's COUNTIF function alone cannot handle OR logic—it only evaluates a single condition. To count cells meeting any of multiple criteria (e.g., 'Apples' or 'Oranges'), you must combine COUNTIF with other functions like SUM or SUMPRODUCT. This guide shows exactly how to do it reliably in modern Excel versions (Microsoft 365, Excel 2021, Excel 2019 and later).

What You'll Need

  • Microsoft Excel (any recent version: Microsoft 365, 2021, 2019, or 2016)
  • A dataset with text or numeric values you want to count
  • No add-ins or special permissions required

Step-by-Step

  1. Identify your range and criteria. Decide which column or row contains the values you’re counting (e.g., A2:A100 for product names) and what the OR conditions are (e.g., "Apples" or "Bananas"). Ensure your data has no accidental spaces or inconsistent formatting—"Apples " (with a trailing space) won’t match "Apples".
  2. Use SUM with multiple COUNTIF functions for simple OR logic. In an empty cell (e.g., D2), enter: =SUM(COUNTIF(A2:A100,"Apples"),COUNTIF(A2:A100,"Bananas")). This counts rows where A2:A100 equals "Apples" plus rows where it equals "Bananas". Press Enter. This is the most straightforward method for up to 3–4 criteria.
  3. For more criteria, use an array constant inside SUMPRODUCT. If you have many conditions (e.g., "Apples", "Bananas", "Cherries", "Dates"), enter: =SUMPRODUCT(--((A2:A100="Apples")+(A2:A100="Bananas")+(A2:A100="Cherries")>0)). The (+) symbols create an OR condition: if any condition is TRUE (1), the sum is ≥1; the double unary (--) converts TRUE/FALSE to 1/0, and SUMPRODUCT adds them. Adjust the ranges and criteria as needed.
  4. Alternative: Use COUNTIFS with helper columns. Insert a new column (e.g., B) next to your data. In B2, enter: =OR(A2="Apples",A2="Bananas"), then drag down. Now use =COUNTIF(B2:B100,TRUE) to get the OR count. This is helpful for auditing or reusing the condition elsewhere, though it adds a column.
  5. Use wildcards for partial matches in OR. To count cells starting with "Ap" or containing "nan", use: =SUM(COUNTIF(A2:A100,"Ap*"),COUNTIF(A2:A100,"*nan*")). Wildcards like * (any characters) and ? (single character) work inside COUNTIF, but be cautious—"Ap*" matches "Apple", "Apex", etc., so verify your pattern isn’t over-inclusive.
  6. Test with a small dataset first. Copy 5–10 rows of your data into a new sheet or area, apply your formula, and manually verify the count. This catches errors like mismatched quotes, incorrect ranges, or hidden characters before scaling up.

Common Mistakes

  • Using COUNTIFS for OR: COUNTIFS uses AND logic by default (all criteria must be true for the same row). Trying =COUNTIFS(A2:A100,"Apples",A2:A100,"Bananas") will return 0 because no cell can be both values simultaneously.
  • Missing quotes around text criteria: COUNTIF("Apples") fails—text must be in double quotes: "Apples". Numeric criteria like >10 need quotes only in text context (e.g., ">10").
  • Range mismatches: If your criteria range is A2:A100 but your formula references A1:A100, the first row (A1) might be included unintentionally, skewing counts.
  • Case sensitivity: COUNTIF is not case-sensitive. "APPLE" and "apple" both match "Apples". If you need case-sensitive OR, use SUMPRODUCT with EXACT: =SUMPRODUCT(--((EXACT(A2:A100,"Apples"))+(EXACT(A2:A100,"apples"))>0)).
  • Empty or error cells: If your range contains #N/A or #VALUE!, formulas may error. Wrap ranges in IFERROR or filter out errors first (e.g., using FILTER in Microsoft 365).

Tips

  • Store criteria in cells for flexibility. Put your values in D1="Apples" and D2="Bananas", then use: =SUM(COUNTIF(A2:A100,D1),COUNTIF(A2:A100,D2)). Change D1 or D2 without editing the formula.
  • Combine with filtering. After counting, use Excel’s Filter (Data > Filter) to visually confirm which rows were included. This helps verify your logic.
  • Use named ranges. Select A2:A100, type "Products" in the Name Box (left of the formula bar), then use =SUM(COUNTIF(Products,"Apples"),COUNTIF(Products,"Bananas")). This makes formulas easier to read and maintain.
  • Check for leading/trailing spaces. Use =TRIM(A2) in a helper column to clean text, or apply TRIM directly in COUNTIF: =SUM(COUNTIF(A2:A100,"Apples"),COUNTIF(TRIM(A2:A100),"Bananas")) (note: array formula in older Excel may require Ctrl+Shift+Enter).
  • For dynamic ranges, use Excel Tables . Convert your data to a table (Ctrl+T), name it "SalesData", and use structured references: . The range auto-expands as you add rows.

Troubleshooting

  • Formula returns 0 when it shouldn’t. First, check if any cells contain extra characters (e.g., "Apples " vs "Apples"). Use =LEN(A2) and compare lengths to spot inconsistencies. Also, verify criteria spelling exactly matches (use F2 to edit a cell and see hidden characters).
  • Formula shows #VALUE! error. This often means your range includes non-numeric data in a context expecting numbers, or you used text without quotes. Ensure all text criteria are in quotes and ranges are consistent (e.g., no merged cells in the range).
  • SUMPRODUCT gives wrong count. Double-check that your TRUE/FALSE logic uses addition (+) for OR and the double unary (--). A common fix is: =SUMPRODUCT((A2:A100="Apples")+(A2:A100="Bananas")) (no >0 needed), but add >0 if you want to avoid double-counting rows matching both (though rare for text OR).
  • Formula works in one sheet but not another. Confirm the sheet name is included if referencing externally: e.g., =SUM(COUNTIF(Sheet2!A2:A100,"Apples"),...).
  • Older Excel versions (pre-2021) behave differently. SUMPRODUCT works universally, but dynamic arrays (e.g., FILTER) require Microsoft 365. If using Excel 2016 or earlier, avoid newer functions like UNIQUE or XLOOKUP in combo.

Frequently Asked Questions

Can COUNTIF handle OR logic by itself?

No—COUNTIF only evaluates one condition. You must combine it with SUM, SUMPRODUCT, or helper columns to simulate OR logic.

Does COUNTIF work with dates?

Yes, but format dates consistently. Use =COUNTIF(A2:A100,">="&DATE(2024,1,1)) for dates on or after Jan 1, 2024. For OR (e.g., Jan or Feb), use =SUM(COUNTIF(A2:A100,">="&DATE(2024,1,1)),COUNTIF(A2:A100,">="&DATE(2024,2,1)),COUNTIF(A2:A100,">="&DATE(2024,3,1))) and adjust carefully to avoid overlap—helper columns with =MONTH(A2) are often cleaner.

How do I count blanks or non-blanks with OR?

Use =SUM(COUNTIF(A2:A100,""),COUNTIF(A2:A100,"<>*")). The first counts empty cells; the second counts non-empty (non-blank) cells, so the sum equals the total rows in the range.

Can I use cell references for criteria in SUM(COUNTIF(...))?

Yes. If D1 contains "Apples" and D2 contains "Bananas", use =SUM(COUNTIF(A2:A100,D1),COUNTIF(A2:A100,D2)). This makes the formula editable without rewriting it.

Why does my COUNTIF count more than expected?

Most likely, criteria like "A*" match "Apple", "Apricot", and "Avocado". Limit wildcards or use exact matches (e.g., "Apples" without wildcards). Also, check for hidden characters using TRIM or LEN.

Does this work in Google Sheets?

Yes—Google Sheets supports the same formulas. However, Google Sheets’ COUNTIF is case-sensitive in some contexts, so test with mixed-case data if precision matters.