Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

COUNTIF in Excel: How to Count Cells with Criteria

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The COUNTIF function in Excel is used to count the number of cells within a specific range that meet a single, defined criterion. For example, if you have a list of sales and want to know how many were made by a specific employee, or if you have a list of students and want to count how many scored above 70, COUNTIF provides the answer instantly without requiring you to manually filter or sort your data. It is a fundamental tool for data analysis that transforms a raw list into meaningful statistics.

What You'll Need

  • A computer with Microsoft Excel installed (works on Excel 365, 2021, 2019, 2016, and earlier versions).
  • A dataset consisting of a range of cells containing the values you wish to count.
  • A clear understanding of the specific condition (the criterion) you want to use to filter your count.

Step-by-Step

  1. Identify your data range: Locate the column or row that contains the information you want to analyze. For instance, if your list of product names is in cells A2 through A50, your range is A2:A50.
  2. Select the destination cell: Click on the empty cell where you want the final count to appear. This is usually a cell adjacent to your data or in a summary table.
  3. Enter the function start: Type =COUNTIF( into the cell. The equals sign tells Excel you are starting a formula, and the open parenthesis begins the argument list.
  4. Define the Range: While the parenthesis is open, highlight the cells you want to search with your mouse, or type the range manually (e.g., A2:A50). After the range, type a comma (or a semicolon, depending on your regional system settings).
  5. Define the Criteria: This is the condition the cell must meet to be counted. There are three primary ways to enter this:
    • Text: To count cells that say "Completed", type "Completed". Text must always be enclosed in double quotation marks.
    • Numbers: To count cells that equal 100, type 100. Numbers do not require quotation marks unless they are part of a logical expression.
    • Cell Reference: Instead of typing the word, click on a cell that contains the word you are looking for (e.g., B1). This makes your formula dynamic; if you change the value in B1, the count updates automatically.
  6. Close and Execute: Type the closing parenthesis ) and press Enter. Excel will now scan the range and display the total number of cells that match your criteria.

Common Mistakes

One of the most frequent errors when using COUNTIF is forgetting the double quotation marks around text criteria. If you type =COUNTIF(A2:A50, Completed) instead of =COUNTIF(A2:A50, "Completed"), Excel will look for a named range called "Completed" rather than the word itself, resulting in a #NAME? error.

Another common mistake is including the header row in the range. While this usually doesn't break the formula, it can lead to inaccurate counts if your header happens to match your criteria. For example, if your header is "Status" and you are counting cells that contain the letter "S", the header will be counted as a match.

Users also often confuse COUNTIF with COUNTIFS. COUNTIF only supports one single condition. If you try to add a second range and a second criterion inside a COUNTIF formula, Excel will return a "Too many arguments" error. For multiple conditions, you must switch to the COUNTIFS function.

Spacing is another silent killer of accuracy. Excel treats "Apple " (with a trailing space) and "Apple" (without a space) as two different values. If your data was imported from another software, it might contain hidden spaces that prevent COUNTIF from finding matches, leading to a result of 0 when you know the data exists.

Tips

To make your COUNTIF formulas more powerful, use logical operators. You can count values that are not equal to a specific item by using the <> symbol. For example, =COUNTIF(A2:A50, "<>Completed") will count everything except the cells that say "Completed".

For numerical ranges, use operators like greater than (>) or less than (<) inside quotation marks. To count all sales over $500, use =COUNTIF(B2:B50, ">500"). If you want to link this to a cell, you must use the ampersand symbol to join the operator and the cell: =COUNTIF(B2:B50, ">" & C1), where C1 contains the number 500.

Wildcards are incredibly useful for partial matches. The asterisk (*) represents any number of characters. If you want to count all cells that start with "North" (like North America, North Pole, North Dakota), use =COUNTIF(A2:A50, "North*"). If you want to count any cell that contains the word "East" anywhere in the text, use =COUNTIF(A2:A50, "*East*").

To keep your spreadsheets clean, avoid hard-coding your criteria inside the formula. Instead, create a small table of the items you want to count and use cell references. This allows you to see a full summary table where the labels are in one column and the COUNTIF results are in the next, making the data much easier to present to others.

Troubleshooting

If your formula is returning 0 but you can clearly see the values in your sheet, the first thing to check is for leading or trailing spaces. You can test this by clicking a cell and checking the formula bar to see if there is a space after the text. To fix this globally, you can use the TRIM function in a helper column to remove extra spaces before running your COUNTIF.

If you see a #VALUE! error, check that your range is valid. This often happens if the range refers to a different sheet that has been deleted or if the range is corrupted. Ensure the range is a simple block of cells (e.g., A1:A100) and not a complex, non-contiguous selection.

If the formula is returning a number that seems too high, check if you have duplicate data or if your criteria are too broad. For example, using a wildcard like "*a*" will count every single cell that contains the letter 'a', which might be almost every cell in a text-based column.

If the formula is not updating when you change the data, check your Calculation Options. Go to the Formulas tab, click Calculation Options, and ensure it is set to Automatic. If it is set to Manual, the COUNTIF result will only change when you press F9.

Frequently Asked Questions

Can COUNTIF count blank cells?

Yes, but it is easier to use the COUNTBLANK function. However, if you must use COUNTIF, you can use "" as the criterion to count empty cells.

Is COUNTIF case-sensitive?

No, COUNTIF is not case-sensitive. It treats "APPLE", "apple", and "Apple" as the exact same value.

Can I count cells based on a color?

No, the COUNTIF function cannot detect cell formatting, such as fill color or font color. To count by color, you would need to use a Filter and the SUBTOTAL function, or write a custom VBA macro.

What is the difference between COUNT and COUNTIF?

The COUNT function counts all cells in a range that contain numbers, regardless of their value. COUNTIF counts only the cells that meet a specific condition you define.

Can I use a date as a criterion?

Yes. You can type the date in quotes, such as "1/1/2023", or better yet, refer to a cell that contains a date. You can also use operators like ">1/1/2023" to count all dates after a certain point.

Does COUNTIF work across different worksheets?

Yes. When selecting your range, you can click over to another sheet. The formula will look like =COUNTIF(Sheet2!A2:A50, "Criteria").