How to Count Cells Equal To This Or That in Excel

Learn multiple Excel methods to count cells equal to specific values—one, the other, or both—with step-by-step examples, troubleshooting advice, and best practices.

excelformulaspreadsheettutorial
11 min read • Last updated: 7/2/2025

How to Count Cells Equal To This Or That in Excel

Why This Task Matters in Excel

Counting how many times specific values appear in a list sounds deceptively simple, yet it powers a surprising number of real-world analytics workflows. Imagine a sales manager tracking how many deals are in “Closed Won” or “Closed Lost,” an HR analyst monitoring employee responses of “Yes” or “Maybe” to a training invitation, or a customer-service lead measuring how many tickets are tagged “Urgent” or “High.” In each scenario, the business decision hinges on quickly quantifying the presence of two (or more) discrete labels.

Excel excels at this problem because its grid paradigm closely mirrors the way raw operational data is stored: every transaction, employee, or ticket is already one row in a table, and category labels occupy a single column. By harnessing Excel’s counting functions you can convert raw lists into insights without manual tallies, pivot tables, or lengthy exports to other software.

Failing to master this simple task introduces hidden costs. Without fast counts you may resort to filtering and eyeballing totals, a repetitive activity that drains time and invites errors. Reports become delayed, dashboards remain static, and leaders make decisions on stale numbers. Moreover, counting specific labels is foundational to more advanced analytics—conditional formatting, custom KPIs, and dynamic dashboards often reference the same totals. Mastering the “count equal to this or that” pattern therefore unlocks a whole family of Excel skills, from interactive slicers to automated email alerts driven by VBA.

In practice you’ll meet this need across industries: manufacturing quality logs requiring counts of “Pass” or “Fail,” education gradebooks tallying “A” or “B,” or retail inventories differentiating “In Stock” and “Backordered.” Because these categories are mutually exclusive values in one column, the problem can be solved with elegant, standard Excel formulas. Whether you are an entry-level analyst or a seasoned financial modeller, reliably counting two labels is a bedrock competency that keeps your spreadsheets lean, automated, and audit-ready.

Best Excel Approach

The most broadly compatible solution combines two COUNTIF functions and simply adds their results:

=COUNTIF([Range],"FirstValue") + COUNTIF([Range],"SecondValue")

Why is this method recommended?

  1. Simplicity – Even novice users grasp one-condition COUNTIF; duplicating the function for the second condition preserves readability.
  2. Compatibility – Works unchanged from Excel 2007 through Microsoft 365, on Windows, macOS, and even Excel for the web.
  3. Performance – Each COUNTIF scans the range once; on modern machines this is negligible overhead for thousands of rows.
  4. No Array Entry Needed – The formula is entered normally; no Control + Shift + Enter requirement.

When should you look elsewhere? Use alternatives if

  • You need to count many (>2) values,
  • You prefer a single formula cell in Microsoft 365 dynamic array versions, or
  • You require case-sensitive matching or more complex logical tests.

For those cases, COUNTIFS with an array constant or SUMPRODUCT offers flexibility:

=COUNTIFS([Range],{"FirstValue","SecondValue"})

(Available in Microsoft 365 and Excel 2021 because it spills the two counts automatically.)

=SUMPRODUCT(--(([Range]="FirstValue") + ([Range]="SecondValue")>0))

SUMPRODUCT is slower but handles legacy environments where spilling is not available and can be extended to extra Boolean logic.

Parameters and Inputs

  • Range to Count [Range]
    – A contiguous column or row such as [B2:B5000].
    – Must contain the values you want to evaluate (text, numbers, or dates).
    – Avoid blank header rows inside the selection; blanks are tolerated but can mislead if you later replace them with data.

  • FirstValue / SecondValue
    – Exact text strings in double quotes (\"Closed Won\"), numbers without quotes (10), or cell references (E1, F1).
    – Comparison is not case sensitive for COUNTIF/COUNTIFS; “Apple” equals “apple.” Use EXACT inside SUMPRODUCT for strict case matching.

  • Optional Wildcards
    – Use an asterisk () to match any series of characters, or a question mark (?) for a single character, e.g., \"Pro\" to match “Product A” and “Project X.”
    – Escape literal asterisks or question marks with a tilde (~).

Data Preparation Tips

  • Trim leading/trailing spaces (TRIM) to reduce miscounts.
  • Ensure cells are stored as the intended data type; numbers formatted as text will not match numeric criteria.
  • Watch mixed data in the same column, especially if importing from CSV.

Edge Cases

  • Empty strings count as text; if you intend to ignore blanks, add a third criterion "<>"" in COUNTIFS or incorporate LEN()>0 logic in SUMPRODUCT.
  • #N/A errors inside the range are ignored by COUNTIF but propagate in SUMPRODUCT, so wrap the Boolean test with IFERROR(...,0) if necessary.

Step-by-Step Examples

Example 1: Basic Scenario – Counting “Yes” or “No” Survey Responses

Suppose column B holds raw answers from an employee survey in rows 2-101: “Yes,” “No,” or left blank if the employee skipped the question. You need to know how many answered either “Yes” or “No” so you can calculate the non-response rate.

  1. Select cell D2 and enter the classic dual COUNTIF approach:
=COUNTIF([B2:B101],"Yes") + COUNTIF([B2:B101],"No")
  1. Press Enter. Excel returns a single number, for instance 87.

  2. Compute the non-response count in D3 with:

=COUNTA([B2:B101]) - D2

Why this works: Each COUNTIF evaluates its criterion independently. Adding them does not double-count because no cell can simultaneously equal both “Yes” and “No.”

Troubleshooting

  • If the total seems low, look for accidental trailing spaces (e.g., “Yes ”). Fix with TRIM or clean in Power Query.
  • If blanks are mistakenly counted, confirm no invisible characters exist; LEN(B2) should return 0 for empty cells.

Common Variation
Need to count “Yes,” “No,” and “Maybe”? Simply extend the pattern:

=COUNTIF([B2:B101],"Yes") + COUNTIF([B2:B101],"No") + COUNTIF([B2:B101],"Maybe")

Example 2: Real-World Application – Inventory Status Dashboard

Context: A retail chain tracks item availability in Sheet “Inventory” column G, using labels “In Stock,” “Backordered,” “Discontinued.” Regional managers want a live count of products that are either “Backordered” or “Discontinued” to prioritize supplier follow-ups. Microsoft 365 is deployed, so dynamic arrays are available.

  1. In the summary Sheet “Dashboard,” select cell B4.
  2. Enter the spilling COUNTIFS formula:
=COUNTIFS(Inventory!G:G,{"Backordered","Discontinued"})
  1. Because of the array constant, Excel returns two numbers, spilling vertically:
  • B4 shows the Backordered count,
  • B5 shows the Discontinued count.
  1. Sum those in B6 for the combined critical items:
=SUM(B4:B5)

Alternative single-cell solution (no spill) using SUM:

=SUM(COUNTIFS(Inventory!G:G,{"Backordered","Discontinued"}))

Integration with Other Features

  • Feed B6 into a traffic-light conditional format: green ≤ 100, yellow ≤ 250, red above 250.
  • Use the same criteria inside FILTER to return the actual list of SKUs needing attention.

Performance Considerations
Full-column references (G:G) are safe in modern Excel, yet for millions of rows limit the range to the used area [G2:G50000]. This avoids scanning empty rows and speeds up recalc on shared workbooks.

Example 3: Advanced Technique – Case-Sensitive Dual Match with Error Handling

A legal department maintains a master log of case statuses in [D2:D1500]. They must count files labeled exactly “Open” or “OPEN” because uppercase denotes escalated priority, while mixed-case labels like “Open – pending” should not be counted. Classic functions are case-insensitive, so COUNTIF will lump them together.

Solution: SUMPRODUCT plus EXACT, wrapped in ISNUMBER to handle possible errors.

  1. In cell H2 enter:
=SUMPRODUCT(--(EXACT(D2:D1500,"Open")) + --(EXACT(D2:D1500,"OPEN")))

Explanation:

  • EXACT returns TRUE if the cell text matches the target string with identical case.
  • The double unary (--) coerces TRUE/FALSE to 1/0.
  • Adding the two arrays produces 1 where either condition is met, 0 elsewhere.
  • SUMPRODUCT sums the resulting array.
  1. Guarding against unexpected errors such as #N/A in the column, adjust with IFERROR:
=SUMPRODUCT(--(IFERROR(EXACT(D2:D1500,"Open"),FALSE)) + --(IFERROR(EXACT(D2:D1500,"OPEN"),FALSE)))

Performance Optimization

  • Limit the range to actual rows via structured tables (Cases[Status]), ensuring dynamic resizing without excess blanks.
  • If the workbook grows, convert the formula into a defined Name and reference it in dashboards to avoid duplication.

Professional Tips

  • Document the rationale (“case distinguishes escalation level”) in a comment so future analysts do not convert back to COUNTIF.
  • Pair with a data-validation dropdown that enforces correct casing at entry, reducing reliance on complex formulas.

Tips and Best Practices

  1. Use Named Ranges or Tables – Replace [A2:A1000] with Sales[Status]; formulas become self-documenting and auto-expand when rows are appended.
  2. Avoid Hard-Coding Strings – Store “Closed Won” and “Closed Lost” in helper cells (Settings sheet) and reference them; this supports quick changes without editing every formula.
  3. Leverage Wildcards Wisely – Combine COUNTIF with \"Pro*\" to summarize product families but document the pattern to prevent unintended matches.
  4. Cache Counts in Helper Columns – For massive datasets, precompute a Boolean “Target?” column and sum it; recalc becomes O(n) once instead of per distinct report cell.
  5. Audit with Conditional Formatting – Highlight any cell matching your criteria to visually confirm the formula’s logic during testing.
  6. Wrap in LET (Microsoft 365) – Assign subexpressions like rng := Data[Status] once, then reuse, enhancing readability and speed.

Common Mistakes to Avoid

  1. Using COUNTIFS with Two Separate Criteria in the Same Column
    COUNTIFS applies an AND relationship by default, so COUNTIFS(Status,"Open",Status,"Closed") always returns zero. Solution: split into two COUNTIF calls or use array constants.

  2. Ignoring Hidden Spaces
    Imported systems often append non-breaking spaces. Detect with LEN(); fix with CLEAN() or Power Query’s Trim.

  3. Full-Column References in Volatile Workbooks
    On older versions or shared network drives, referencing A:A can slow recalculation. Limit to used rows or turn the range into an Excel Table.

  4. Overlooking Case Sensitivity Requirements
    Default functions are not case sensitive—validate whether that matches business rules. When needed, switch to EXACT-based formulas.

  5. Hard-Coding Criteria in Multiple Places
    This makes maintenance painful and error-prone. Centralize criteria in a control panel sheet and reference them.

Alternative Methods

MethodExcel VersionSyntax ExampleProsCons
Dual COUNTIF + addition2007+`=COUNTIF(`rng,\"A\")+COUNTIF(rng,\"B\")Easiest to read, universalOne function per value, manual edits if criteria list grows
COUNTIFS with array constant365, 2021`=SUM(`COUNTIFS(rng,[\"A\",\"B\"]))One compact formula, spills per valueNot available in older versions
SUMPRODUCT Boolean logic2007+`=SUMPRODUCT(`--((rng=\"A\")+(rng=\"B\")>0))Single cell, supports complex logic, optional case-sensitiveSlightly slower, syntax less intuitive
PivotTable with filtersAllDrag field to Values area, set “A” and “B” filterNo formulas, interactiveManual refresh, less dynamic inside formulas
Power Query Group By2016+M codeHandles millions of rows, reproducible ETLRequires refresh, output static unless loaded to data model

When dealing with more than two criteria or non-equal comparisons (greater than thresholds, dates), consider a PivotTable or Power Query as they scale better and separate calculation from presentation.

FAQ

When should I use this approach?

Use these formulas anytime you must quickly quantify two discrete categories in the same column—status codes, survey answers, yes/no flags—especially when the counts feed other formulas or dashboards.

Can this work across multiple sheets?

Yes. Reference each sheet’s range and add the results:

=COUNTIF(Sheet1!C:C,"A")+COUNTIF(Sheet2!C:C,"A")  
   +COUNTIF(Sheet1!C:C,"B")+COUNTIF(Sheet2!C:C,"B")

For many sheets, consider 3D references or consolidate data into one table.

What are the limitations?

COUNTIF cannot be both case-sensitive and wildcard-enabled simultaneously. COUNTIFS with array constants is unavailable before Excel 2021. Extremely large ranges (millions of rows) may cause sluggish recalc; offload to Power Pivot for better performance.

How do I handle errors?

Wrap the range in IFERROR(range,"") inside SUMPRODUCT, or clean the data so error cells convert to blanks. For COUNTIF, errors are ignored automatically.

Does this work in older Excel versions?

Dual COUNTIF and SUMPRODUCT formulas operate back to Excel 2003 (with Function Wizard). Array constants in COUNTIFS and dynamic arrays require Microsoft 365 or Excel 2021.

What about performance with large datasets?

Minimize recalculation by:

  1. Limiting the counted range,
  2. Using Tables with structured references,
  3. Switching to Data Model (Power Pivot) where calculations are columnar and cached, or
  4. Performing ETL in Power Query and loading aggregated results.

Conclusion

Counting cells equal to “this or that” is a deceptively powerful technique underpinning dashboards, KPIs, and everyday ad-hoc analysis. Mastering the dual COUNTIF pattern gives you a portable, low-maintenance solution, while understanding COUNTIFS, SUMPRODUCT, PivotTables, and Power Query equips you for specialized or large-scale tasks. Add these methods to your Excel toolbox, practice on real datasets, and you’ll transform raw labels into actionable numbers faster and more reliably than ever. Dive into your own spreadsheets today and start automating those counts!

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.