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.
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 COUNTIF function in Microsoft Excel is:
COUNTIF( range, criteria )
The syntax for the COUNTIF function in Microsoft Excel is:
COUNTIF( range, criteria )
Parameters or Arguments
- range
- The range of cells that you want to count based on the criteria.
- criteria
- The criteria used to determine which cells to count.
- range
- The range of cells that you want to count based on the criteria.
- criteria
- The criteria used to determine which cells to count.
Applies To
- Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
- Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Function
- Worksheet function (WS)
- Worksheet function (WS)
Example (as Worksheet Function)
Let's look at some Excel COUNTIF function examples and explore how to use the COUNTIF function as a worksheet function in Microsoft Excel:
Based on the Excel spreadsheet above, the following COUNTIF examples would return:
=COUNTIF(A2:A7, D2)
Result: 1
=COUNTIF(A:A, D2)
Result: 1
=COUNTIF(A2:A7, ">=2001")
Result: 4
Let's look at some Excel COUNTIF function examples and explore how to use the COUNTIF function as a worksheet function in Microsoft Excel:
Based on the Excel spreadsheet above, the following COUNTIF examples would return:
=COUNTIF(A2:A7, D2) Result: 1 =COUNTIF(A:A, D2) Result: 1 =COUNTIF(A2:A7, ">=2001") Result: 4
Using Named Ranges
You can also use a named range in the COUNTIF function. A named range is a descriptive name for a collection of cells or range in a worksheet. If you are unsure of how to setup a named range in your spreadsheet, read our tutorial on Adding a Named Range.
For example, we've created a named range called family that refers to column A in Sheet 1.
Then we've entered the following data in Excel:
Based on the Excel spreadsheet above:
=COUNTIF(family, D2)
Result: 1
=COUNTIF(family, ">=2001")
Result: 4
To view named ranges: Under the Insert menu, select Name > Define.
You can also use a named range in the COUNTIF function. A named range is a descriptive name for a collection of cells or range in a worksheet. If you are unsure of how to setup a named range in your spreadsheet, read our tutorial on Adding a Named Range.
For example, we've created a named range called family that refers to column A in Sheet 1.
Then we've entered the following data in Excel:
Based on the Excel spreadsheet above:
=COUNTIF(family, D2) Result: 1 =COUNTIF(family, ">=2001") Result: 4
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?
Here's an example of what I'd like to be able to do:
=COUNTIF(A2,A5,F6,G9,">0")
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)
Question:I would like to do the following:
=COUNTIF(ABS(A1:A10),">0")
i.e. count the number of values in the range A1:A10 that have a non-zero magnitude. The syntax I tried does not work. Could you help?
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")
This will count the number of values that are either greater than 0 or less than 0.
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?
Here's an example of what I'd like to be able to do:
=COUNTIF(A2,A5,F6,G9,">0")
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)
Question:I would like to do the following:
=COUNTIF(ABS(A1:A10),">0")
i.e. count the number of values in the range A1:A10 that have a non-zero magnitude. The syntax I tried does not work. Could you help?
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")
This will count the number of values that are either greater than 0 or less than 0.