0% found this document useful (0 votes)
2K views13 pages

Count If

The COUNTIF function counts the number of cells within a range that meet criteria. It has the syntax COUNTIF(range, criteria) where range is the cells to count and criteria is what defines which cells will be counted, such as a number, cell reference, or text. COUNTIFS allows counting cells where multiple criteria are met, with the syntax COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2). Examples show using COUNTIF to count cells containing specific text and numbers, and COUNTIFS to count cells meeting two criteria, like a name and region.

Uploaded by

Noraini Mohd Nor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views13 pages

Count If

The COUNTIF function counts the number of cells within a range that meet criteria. It has the syntax COUNTIF(range, criteria) where range is the cells to count and criteria is what defines which cells will be counted, such as a number, cell reference, or text. COUNTIFS allows counting cells where multiple criteria are met, with the syntax COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2). Examples show using COUNTIF to count cells containing specific text and numbers, and COUNTIFS to count cells meeting two criteria, like a name and region.

Uploaded by

Noraini Mohd Nor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

COUNTIF

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.

Example 1: Common COUNTIF formulas


The example may be easier to understand if you copy it to a blank worksheet. How to copy an example

A 1 2 3 4 5 oranges peaches Data apples

B Data 32 54 75

apples Formula =COUNTIF(A2:A5,"apples") =COUNTIF(A2:A5,A4) =COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2) =COUNTIF(B2:B5,">55") =COUNTIF(B2:B5,"<>"&B4) =COUNTIF(B2:B5,">=32")COUNTIF(B2:B5,">85")

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

A 1 2 3 4 5 6 7 apples Formula =COUNTIF(A2:A7,"*es") =COUNTIF(A2:A7,"?????es") oranges peaches Data apples

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%)

=COUNTIF(B2:B7,"Yes") / (ROWS(B2:B7) -COUNTIF(B2:B7, "<>"&"*"))


NOTE

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.

MS EXCEL: COUNTIF FUNCTION (WS)


Learn how to use the Excel COUNTIF function with syntax and examples.

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

TYPE OF EXCEL FUNCTION


The COUNTIF function can be used in Microsoft Excel as the following type of function:

Worksheet function (WS)

EXAMPLE (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 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.

Then we've entered the following data in Excel:

Based on the Excel spreadsheet above:


=COUNTIF(family, D2) =COUNTIF(family, ">=2001") would return 1 would return 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?
6

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")
7

This will count the number of values that are either greater than 0 or less than 0. ___________________________________________________________________________

Excel COUNTIF and COUNTIFS Formulas Explained


In this Microsoft Office tutorial were looking at the COUNTIF and COUNTIFS Formulas, and well take a look at a couple of different applications for them. Plus download a practice workbook so you can learn by reverse engineering the formulas used in this example. Note: this is an Excel .xlsx workbook. Please ensure your browser doesnt change the file extension on download. The COUNTIF/S formulas work ALMOST in the same way as the SUMIF/S formulasonly theyre slightly simpler. So if you havent mastered SUMIF/S yet be sure to check out our SUMIF/S tutorial too. The COUNTIF extends the capabilities of the basic COUNT formula by allowing you to tell Excel to only COUNT items that meet a certain criteria. New in Excel 2007 is the COUNTIFS formula, which allows you to stipulate multiple criteria, hence the plural. Enough explanation, lets dive into an example as its easier to visualise.

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.

Translated our formula would read like this:

=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:

Our formula in cell C12 would be:

=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

You might also like