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.
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?
- Simplicity – Even novice users grasp one-condition
COUNTIF; duplicating the function for the second condition preserves readability. - Compatibility – Works unchanged from Excel 2007 through Microsoft 365, on Windows, macOS, and even Excel for the web.
- Performance – Each
COUNTIFscans the range once; on modern machines this is negligible overhead for thousands of rows. - 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 forCOUNTIF/COUNTIFS; “Apple” equals “apple.” UseEXACTinsideSUMPRODUCTfor 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
"<>""inCOUNTIFSor incorporateLEN()>0logic inSUMPRODUCT. #N/Aerrors inside the range are ignored byCOUNTIFbut propagate inSUMPRODUCT, so wrap the Boolean test withIFERROR(...,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.
- Select cell D2 and enter the classic dual
COUNTIFapproach:
=COUNTIF([B2:B101],"Yes") + COUNTIF([B2:B101],"No")
-
Press Enter. Excel returns a single number, for instance 87.
-
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
TRIMor 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.
- In the summary Sheet “Dashboard,” select cell B4.
- Enter the spilling
COUNTIFSformula:
=COUNTIFS(Inventory!G:G,{"Backordered","Discontinued"})
- Because of the array constant, Excel returns two numbers, spilling vertically:
- B4 shows the Backordered count,
- B5 shows the Discontinued count.
- 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
FILTERto 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.
- In cell H2 enter:
=SUMPRODUCT(--(EXACT(D2:D1500,"Open")) + --(EXACT(D2:D1500,"OPEN")))
Explanation:
EXACTreturns 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.
SUMPRODUCTsums the resulting array.
- Guarding against unexpected errors such as
#N/Ain the column, adjust withIFERROR:
=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
- Use Named Ranges or Tables – Replace [A2:A1000] with Sales[Status]; formulas become self-documenting and auto-expand when rows are appended.
- 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.
- Leverage Wildcards Wisely – Combine
COUNTIFwith \"Pro*\" to summarize product families but document the pattern to prevent unintended matches. - 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.
- Audit with Conditional Formatting – Highlight any cell matching your criteria to visually confirm the formula’s logic during testing.
- Wrap in
LET(Microsoft 365) – Assign subexpressions likerng := Data[Status]once, then reuse, enhancing readability and speed.
Common Mistakes to Avoid
-
Using COUNTIFS with Two Separate Criteria in the Same Column
COUNTIFSapplies an AND relationship by default, soCOUNTIFS(Status,"Open",Status,"Closed")always returns zero. Solution: split into twoCOUNTIFcalls or use array constants. -
Ignoring Hidden Spaces
Imported systems often append non-breaking spaces. Detect withLEN(); fix withCLEAN()or Power Query’s Trim. -
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. -
Overlooking Case Sensitivity Requirements
Default functions are not case sensitive—validate whether that matches business rules. When needed, switch toEXACT-based formulas. -
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
| Method | Excel Version | Syntax Example | Pros | Cons |
|---|---|---|---|---|
Dual COUNTIF + addition | 2007+ | `=COUNTIF(`rng,\"A\")+COUNTIF(rng,\"B\") | Easiest to read, universal | One function per value, manual edits if criteria list grows |
COUNTIFS with array constant | 365, 2021 | `=SUM(`COUNTIFS(rng,[\"A\",\"B\"])) | One compact formula, spills per value | Not available in older versions |
SUMPRODUCT Boolean logic | 2007+ | `=SUMPRODUCT(`--((rng=\"A\")+(rng=\"B\")>0)) | Single cell, supports complex logic, optional case-sensitive | Slightly slower, syntax less intuitive |
| PivotTable with filters | All | Drag field to Values area, set “A” and “B” filter | No formulas, interactive | Manual refresh, less dynamic inside formulas |
| Power Query Group By | 2016+ | M code | Handles millions of rows, reproducible ETL | Requires 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:
- Limiting the counted range,
- Using Tables with structured references,
- Switching to Data Model (Power Pivot) where calculations are columnar and cached, or
- 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!
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.