MS Excel: COUNTIF Function (WS)
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.
COUNTIF Function (Syntax)
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:
- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The COUNTIF function can be used in Microsoft Excel as:
- Worksheet function (WS)
COUNTIF Examples (as Worksheet Function)
Let's look at some Excel COUNTIF function examples and explore how you would use the COUNTIF function as a worksheet function in Microsoft Excel:
Based on the Excel spreadsheet above, the following COUNTIF function examples would return:
|=COUNTIF(A2:A7, D2)||would return 1|
|=COUNTIF(A:A, D2)||would return 1|
|=COUNTIF(A2:A7, ">=2001")||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.
Then we've entered the following data in Excel:
Based on the Excel spreadsheet above:
|=COUNTIF(family, D2)||would return 1|
|=COUNTIF(family, ">=2001")||would return 4|
To view named ranges: Under the Insert menu, select Name > Define.
Frequently Asked Questions (COUNTIF Function)
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.