Learn how to use the Excel COUNTIF function with syntax and examples.
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 syntax for the Microsoft Excel COUNTIF function is:
COUNTIF( range, criteria )
range is the range of cells that you want to count based on the criteria.
criteria is used to determine which cells to count.
The COUNTIF function can be used in the following versions of Microsoft Excel:
The COUNTIF function can be used in Microsoft Excel as the following type of 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 spreadsheet above, the following Excel COUNTIF examples would return:
=COUNTIF(A2:A7, D2) Result: 1 =COUNTIF(A:A, D2) Result: 1 =COUNTIF(A2:A7, ">=2001") Result: 4
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.
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.
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:
Answer: Unfortunately, the COUNTIF function does not support multiple ranges. However, you could try summing multiple COUNTIFs.
Question: I am using the COUNTIF function and I would like to make the criteria equal to a cell.
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:
Question:I would like to do the following:
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:
This will count the number of values that are either greater than 0 or less than 0.