How to Create a COUNTIF Function in Excel

How to Create a COUNTIF Function in Excel

There was a point in my early Excel days when I would manually scroll through hundreds of rows just to count how many times a specific value appeared. It was tedious, error-prone, and honestly a waste of time. The moment I discovered COUNTIF, that whole workflow disappeared. Now I use it almost daily, whether I’m counting how many orders came from a particular city or how many students scored above a certain grade.

This guide breaks down exactly how COUNTIF works, how to write it correctly, and how to avoid the mistakes that trip up most beginners.

What Is the COUNTIF Function in Excel?

COUNTIF counts the number of cells within a range that meet a single condition you specify. Instead of manually tallying values, you give Excel a range and a criterion, and it returns the count instantly. It’s a conditional counting tool, and it’s one of the most widely used functions in reporting, data analysis, and everyday spreadsheet work.

Required Data

To use COUNTIF, you need:

Basic Syntax

=COUNTIF(range, criteria)

Step-by-Step Instructions

  1. Click the cell where you want the count to appear.
  2. Type =COUNTIF(.
  3. Select or type the range you want to search, such as A2:A50.
  4. Add a comma, then type your criteria in quotation marks if it’s text, or without quotes if it’s a plain number.
  5. Close the parenthesis and press Enter.

Example:

=COUNTIF(A2:A50, "Completed")

This counts how many cells in A2:A50 contain the exact text “Completed.”

Practical Examples

Example 1: Counting Exact Text Matches

=COUNTIF(B2:B100, "Pending")

Counts every cell in B2:B100 that says “Pending.”

Example 2: Counting Numbers Greater Than a Value

=COUNTIF(C2:C100, ">50")

Counts how many cells contain a number greater than 50.

Example 3: Counting Cells Equal to a Cell Reference

=COUNTIF(D2:D100, D1)

This counts how many cells match whatever value is in D1, which is useful if you want your criteria to be dynamic rather than hardcoded.

Example 4: Counting With Wildcards

If you want to count cells that contain a certain word anywhere within the text, use an asterisk as a wildcard:

=COUNTIF(E2:E100, "*urgent*")

This counts any cell containing the word “urgent,” regardless of what comes before or after it.

Example 5: Counting Non-Blank Cells

=COUNTIF(F2:F100, "<>")

This counts cells that are not empty.

Example 6: Counting Dates Before a Certain Date

=COUNTIF(G2:G100, "<01/01/2026")

Counts how many dates fall before January 1, 2026.

Common Mistakes to Avoid

  1. Forgetting quotation marks around text criteria — Text criteria must be wrapped in quotes; numbers typically don’t need them unless combined with an operator like “>50”.
  2. Using COUNTIF when multiple conditions are needed — COUNTIF only supports one condition. If you need to count based on two or more criteria, you need COUNTIFS instead.
  3. Case sensitivity confusion — COUNTIF is not case-sensitive, so “Completed” and “completed” are treated the same. If you need case-sensitive counting, you’d need a more advanced formula using EXACT combined with SUMPRODUCT.
  4. Mismatched data types — If dates are stored as text instead of actual date values, comparison operators like “<01/01/2026” won’t work correctly.
  5. Range and criteria mismatch — Make sure the range you’re counting is actually where your data lives; a common error is selecting the wrong column entirely.

Troubleshooting Tips

Real-World Use Cases

Best Practices

Frequently Asked Questions

Can COUNTIF count based on cell color? Not directly. COUNTIF works with values and text, not formatting. To count by color, you’d need a helper column that identifies the color condition, or a small VBA macro, since standard formulas can’t read cell fill color natively.

Does COUNTIF work across multiple sheets at once? No, a single COUNTIF formula only searches one contiguous range on one sheet. To count across several sheets, either consolidate your data into one sheet first, or write a separate COUNTIF for each sheet and add the results together with a plus sign between them.

What’s the difference between COUNTIF and COUNTIFS? COUNTIF handles exactly one condition. COUNTIFS handles two or more conditions simultaneously, checking that all of them are true before counting a row. If you only ever need a single condition, COUNTIF is simpler and slightly faster to type.

Can I use COUNTIF to count unique values? Not on its own, but it’s a common building block for that purpose. A formula like =SUMPRODUCT(1/COUNTIF(A2:A20, A2:A20)) uses COUNTIF internally to calculate a count of unique entries in a range.

Why does my COUNTIF formula count merged cells incorrectly? Merged cells can behave unpredictably with COUNTIF because Excel treats the merged area as belonging to only the top-left cell. It’s generally best practice to avoid merged cells in ranges you plan to run formulas against.

Final Thoughts

COUNTIF is one of those functions that feels simple at first glance but ends up being indispensable once you start using it regularly. It removes the guesswork and manual counting from your workflow and gives you accurate, instant results. Once you’re confident with COUNTIF, learning COUNTIFS for multi-condition counting is a natural next step that will expand what you’re able to analyze in your spreadsheets.

Exit mobile version