Count If
Count If
Show All
Counts the number of cells within a range that meet the given criteria.
Syntax
COUNTIF(range,criteria) Range is the range of cells from which you want to count cells.
Criteria is the criteria in the form of a number, expression, cell reference, or text that defines which cells will be counted. For example, criteria can be expressed as 32, "32", ">32", "apples", or B4.
Remarks
You can use the wildcard characters, question mark (?) and asterisk (*), in criteria. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character. Microsoft Excel provides additional functions that can be used to analyze your data based on a condition. To calculate a sum based on a string of text or a number within a range, use the SUMIF worksheet function. To have a formula return one of two values based on a condition, such as a sales bonus based on a specified sales amount, use the IF worksheet function. To count cells that are empty or not empty, use the COUNTA and COUNTBLANK functions.
B Data 32 54 75
86 Description (result) Number of cells with apples in the first column above (2) Number of cells with peaches in the first column above (1) Number of cells with oranges or apples in the first column above (3) Number of cells with a value greater than 55 in the second column above (2) Number of cells with a value not equal to 75 in the second column above (2) Number of cells with a value greater than or equal to 32 and less than or equal to 85 in the second column above (3)
Example 2: COUNTIF formulas using wildcard characters and handling blank values
The example may be easier to understand if you copy it to a blank worksheet. How to copy an example
B Data Yes
NO No
YeS Description (result) Number of cells ending with the letters "es" in the first column above (4) Number of cells ending with the letters "les" and having exactly 7 letters in the first column above
2
(2) =COUNTIF(A2:A7,"*") =COUNTIF(A2:A7,"<>"&"*") =COUNTIF(B2:B7,"No") / ROWS(B2:B7) Number of cells containing text in the first column above (4) Number of cells not containing text in the first column above (2) The average number of No votes including blank cells in the second column above formatted as a percentage with no decimal places (33%) The average number of Yes votes excluding blank cells in the second column above formatted as a percentage with no decimal places (50%)
To view the number as a percentage, select the cell and click Cells on the Format menu.
Click the Numbertab, and then click Percentage in the Category box.
DESCRIPTION
The Microsoft Excel COUNTIF function counts the number of cells in a range, that meets a given criteria. If you wish to apply multiple criteria, try using the COUNTIFS function.
SYNTAX
The syntax for the Microsoft Excel COUNTIF function is: COUNTIF( range, criteria ) PARAMETERS OR ARGUMENTS range is the range of cells that you want to count based on the criteria. criteria is used to determine which cells to count.
APPLIES TO
The COUNTIF function can be used in the following versions of Microsoft Excel:
Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Based on the spreadsheet above, the following Excel COUNTIF examples would return:
=COUNTIF(A2:A7, D2) =COUNTIF(A:A, D2) =COUNTIF(A2:A7, ">=2001") would return 1 would return 1 would return 4
USING NAMED RANGES You can also use a named range in the COUNTIF function. For example, we've created a named range called family that refers to column A in Sheet 1.
To view named ranges: Under the Insert menu, select Name > Define.
FREQUENTLY ASKED QUESTIONS Question: I'm trying to use COUNTIF on a selection of cells (not necessarily one solid
range), and the syntax of the function does not allow that. Is there another way to do this?
6
Answer: Unfortunately, the COUNTIF function does not support multiple ranges. However,
you could try summing multiple COUNTIFs. For example: =SUM(COUNTIF(A2,">0"),COUNTIF(A5,">0"),COUNTIF(F6,">0"),COUNTIF(G9," >0")) OR =COUNTIF(A2,">0")+COUNTIF(A5,">0")+COUNTIF(F6,">0")+COUNTIF(G9,">0")
Question: I am using the COUNTIF function and I would like to make the criteria equal to a
cell. For example: =COUNTIF(C4:C19,">=2/26/04") I want to replace 2/26/04 with cell A1. How do I do this?
Answer: To use a cell reference in the criteria, you could do the following:
=COUNTIF(C4:C19,">="&A1)
Answer: Because you can not apply the ABS function to range A1:A10, you will need to
instead break up your formula into two COUNTIF functions as follows: =COUNTIF(A1:A10,">0")+COUNTIF(A1:A10,"<0")
7
This will count the number of values that are either greater than 0 or less than 0. ___________________________________________________________________________
COUNTIF:
The function wizard in Excel describes the COUNTIF Formula as:
=COUNTIF(range,criteria)
Looks fairly simple and it is. Lets translate it into English now by applying it to an example. Say we wanted to count the number of times Dave appeared in column C of the table below.
=COUNTIF(count the number of cells in column C, that contain 'Dave') We could even create a table under the data to count the occurrences of each builder:
=COUNTIF(C2:C7,"Dave") While the above formula is good, if we were to copy it to the rest of the summary table (cells C11 to C14) we would have to manually change the cell references and builders name to get the correct answers. To avoid this manual intervention, we can use absolute references, which will speed up the process of copying the formula to the remainder of column C. With absolute references our formula would look like this:
=COUNTIF($C$2:$C$7,$B12)
The $ signs tell Excel that we dont want the reference after the $ sign to change when we copy the formula. For example, if we copied the formula into cell C13 it would read:
10
=COUNTIF($C$2:$C$7,$B13) In the above formula we can see that the only reference that changed was $B12, which became $B13. The best way to understand how this works is to try it for yourself. Download the workbook used in this example here. Note: this is an Excel .xlsx workbook. Please ensure your browser doesnt change the file extension on download. Note: I used a basic example to illustrate how to use the COUNTIF formula, but you could also achieve this count by builder using the subtotal tool in the Data tab.
COUNTIFS
The function wizard in Excel describes the COUNTIFS Formula as:
=COUNTIFS(critera_range_1,criteria_1,criteria_range_2,criteria_2.....and so on if required) Extending the previous COUNTIF example above, say we wanted to only summarise the data by builder for jobs in the South region. We could use the COUNTIFS formula, as it allows us to set more than one condition. Heres how the formula would be interpreted if we wanted to count the occurrences of Brian in column C, where jobs were in the South region:
=COUNTIFS(count the number of cells in column C if, they contain Brian and, if in column B, they are also for the South region) Note: Excel will only include the cells in column C in the count when both conditions (Brian & South) are met. Using absolute references, our formula in Excel cell C20 would read:
=COUNTIFS($C$2:$C$7,$B20,$B$2:$B$7,$B$17)
11
Try other operators Just like the IF Statment and SUMIF formula, the COUNTIF and COUNTIFS are based on logic. This means you can employ different tests other than the text matching (Brian & South) weve used above. Other operators you could use are:
Equal to Less Than Greater Than Less than or equal to Greater than or equal to Less than or greater than
12
For example, if you wanted to count the jobs with an average > $300k the formula would be:
=COUNTIF($E$2:$E$7,">300")
Note: again Ive used a simple example to illustrate this formula, but another way to achieve this summary table for each builder by region is to use a Pivot Table.
13