Excel COUNTIF Yes: How to Count Specific Text Values
In this article
To count the number of times the word "Yes" appears in a range of cells in Excel, use the formula =COUNTIF(range, "Yes"). This function scans a specified group of cells and returns a total count of every cell that matches the exact text string provided in the criteria argument. For example, if your data is in cells A1 through A10, the formula =COUNTIF(A1:A10, "Yes") will tell you exactly how many cells in that range contain the word "Yes".
What You'll Need
- A computer with Microsoft Excel installed (any version from 2007 to the current Microsoft 365 version).
- A dataset containing a column or row of responses (such as "Yes", "No", "Maybe", or "Pending").
- Basic familiarity with how to select a range of cells in a spreadsheet.
Step-by-Step
- Identify your data range: Locate the column or row where your "Yes" values are stored. For this guide, we will assume your data is in column B, from cell B2 to B100.
- Select the output cell: Click on the empty cell where you want the final count to appear. This is typically at the bottom of your data list or in a separate summary table.
- Start the formula: Type the equals sign
=to tell Excel you are starting a calculation. Then typeCOUNTIF(. - Define the range: While the cursor is inside the parentheses, click and drag your mouse over the cells containing the data (B2 to B100), or simply type
B2:B100. This tells Excel where to look for the data. - Add the comma: Type a comma
,to separate the range from the criteria. - Enter the criteria: Type
"Yes". It is critical to put the word Yes inside double quotation marks. In Excel, any text used as a criterion in a formula must be wrapped in quotes, otherwise, Excel will treat it as a named range or a function and return a #NAME? error. - Close the formula: Type the closing parenthesis
)and press the Enter key on your keyboard. - Verify the result: The cell will now display a number representing the total count of cells that exactly match "Yes".
Common Mistakes
One of the most frequent errors users make is forgetting the double quotation marks around the word "Yes". If you type =COUNTIF(A1:A10, Yes), Excel looks for a defined name called "Yes". Since that name usually doesn't exist, the formula fails. Always use "Yes".
Another common mistake is including leading or trailing spaces within the cells. If a cell contains "Yes " (with a space at the end) instead of "Yes", the standard COUNTIF formula will ignore it because it is looking for an exact match. This often happens when data is imported from web forms or other software.
Users also sometimes confuse COUNTIF with COUNTIFS. While COUNTIF is for a single condition, COUNTIFS (with an 'S') is used for multiple conditions. If you only need to count "Yes", using COUNTIFS is unnecessary and can make the formula more complex than it needs to be, although it will still work if you only provide one set of criteria.
Lastly, some users try to apply the formula to an entire column (e.g., B:B) when they have a header row. While this works, if the header itself is named "Yes", the formula will count the header as part of the data, leading to an inflated result. It is always better to define the specific range starting below the header.
Tips
Use Cell References for Flexibility: Instead of hard-coding "Yes" into your formula, you can type the word Yes into a different cell (e.g., cell D1) and change your formula to =COUNTIF(B2:B100, D1). This allows you to quickly change the word in D1 to "No" or "Maybe" to see different counts without editing the formula itself.
Case Sensitivity: It is important to note that COUNTIF is not case-sensitive. This means it will count "YES", "yes", "Yes", and "yEs" all as the same value. If you specifically need to count only uppercase "YES", you would need a more complex formula involving the EXACT function combined with SUMPRODUCT.
Counting "Not Yes": If you want to count every cell that does not say "Yes", you can use the "not equal to" operator. The formula would be =COUNTIF(B2:B100, "<>Yes"). This is incredibly useful for finding missing responses or identifying "No" and "Maybe" answers simultaneously.
Wildcard Usage: If your cells contain phrases like "Yes, I agree" and you want to count any cell that starts with Yes, use a wildcard. The formula =COUNTIF(B2:B100, "Yes*") will count any cell that begins with "Yes" regardless of what follows it.
Troubleshooting
The result is 0, but I can see "Yes" in the cells: This is almost always caused by hidden spaces. To fix this, you can use the TRIM function to clean your data. Select your data, go to the Data tab, and use a helper column with =TRIM(B2) to remove extra spaces, then run the COUNTIF on the cleaned column. Alternatively, try using wildcards: =COUNTIF(B2:B100, "*Yes*"). If this returns a number higher than 0, you definitely have hidden characters or extra text in those cells.
The formula returns #NAME?: Check your quotation marks. Ensure you have used "Yes" and not just Yes. Also, ensure that the function name is spelled correctly as COUNTIF.
The formula returns #VALUE!: This typically occurs if the range you selected is invalid or if the formula is referencing a range across different worksheets in a way that Excel cannot resolve. Ensure your range (e.g., B2:B100) is correct and exists on the current sheet.
The count is higher than expected: Check if your range includes the header row. If your column header is "Yes" (e.g., a column titled "Yes?" or just "Yes"), Excel will count that header. Adjust your range to start from the first row of actual data (e.g., B2 instead of B1).
Frequently Asked Questions
Can I count "Yes" across multiple columns?
Yes, you can. Simply expand the range in the formula to cover multiple columns, such as =COUNTIF(B2:D100, "Yes"). This will count every occurrence of "Yes" across columns B, C, and D.
How do I count "Yes" and "Maybe" at the same time?
You can add two COUNTIF functions together. Use =COUNTIF(B2:B100, "Yes") + COUNTIF(B2:B100, "Maybe"). This calculates the total for each and sums them up.
Does COUNTIF work with checkboxes in Excel?
If you are using the new Insert > Checkbox feature in Excel, the checkbox is actually a visual representation of TRUE or FALSE. To count checked boxes, use =COUNTIF(B2:B100, TRUE). Note that you do not use quotes for TRUE/FALSE because they are logical values, not text.
Can I use this formula in Google Sheets?
Yes, the =COUNTIF() function works identically in Google Sheets. The syntax, range selection, and requirement for quotation marks around text are exactly the same as in Microsoft Excel.
What if I want to count cells that are NOT blank and NOT "No"?
In this case, it is easier to use COUNTIFS. Use =COUNTIFS(B2:B100, "<>No", B2:B100, "<>"). The "<>" symbol tells Excel to ignore blank cells, while "<>No" ignores the "No" entries.