Sie sind auf Seite 1von 34

In this lesson you can learn aboutCOUNTIF function.

COUNTIF function counts the number of times within the specified range of cells that
perform the specified value as a criterion.
Function syntax:
=COUNTIF (range, criteria)

Range - the range of cells that you want to count the data. There has to be an
ongoing area.
Criteria - a condition that must be met for cell counting. In the case of numeric
values - the condition can look like eg 100

Example 1 - count string with exact


string of text
You want to count cells where there is only REPORT text. Cells are in C column.
The formula is =COUNTIF(C2:C10,REPORT)

Example 2 - greater than

You want to count cells where value is greater than 10. Cells are in C column.
The formula is =COUNTIF(C2:C10,">"&10)

Example 3 - greater than or equal to


You want to count cells where value is greater than or equal 10. Cells are in C column.
The formula is =COUNTIF(C2:C10,">="&10)

Example 4 - not equal to


You want to count cells where value is not equal to 10. Cells are in C column.
The formula is =COUNTIF(C2:C10,"<>"&10)

Example 5 - less than x but more than y


You want to count cells where value is less than 40 but more than 15. Cells are in C
column.
The formula is =COUNTIF(C2:C10,"<"&40)-COUNTIF(C2:C10,"<="&15)

Example 6 - countif plus countif


You want to count cells where value is greater than 40 plus less than 15. Cells are in C
column.
The formula is =COUNTIF(C2:C10,">"&40)+COUNTIF(C2:C10,"<"&15)

Example 7 - count cells containing


string of text
You want to count cells which contain REPORT text. Cells are in C column.
Use asterisk in your formula. Asterisk replaces any other signs.
The formula is =COUNTIF(C2:C10,"*REPORT*")

Example 8 - count cells beginning with


string of text
You want to count cells which begin REPORT text. Cells are in C column. Use asterisk
in your formula. Asterisk replaces any other signs.
The formula is =COUNTIF(C2:C10,"REPORT*")

Example 9 - count cells ending with


string of text
You want to count cells which end RT text. Cells are in C column. Use asterisk in your
formula. Asterisk replaces any other signs.
The formula is =COUNTIF(C2:C10,"*RT")

Example 10 - count cells ending with


string of text and contains 6 letters
You want to count cells which end RT text and contains 6 letters. Cells are in C column.
Use question mark in your formula. Question mark replaces one sign.
The formula is =COUNTIF(C2:C10,"????RT")

Example 11 - count cells containing any


text
You want to count cells which contain any text. Cells are in C column. Use asterisk in
your formula. Asterisk replaces any other signs.
The formula is =COUNTIF(C2:C10,"*")

Example 12 - count cells not containing


any text
You want to count cells which not contain any text. Cells are in C column. Use asterisk
in your formula. Asterisk replaces any other signs. <> means not equal to.
The formula is =COUNTIF(C2:C10,"<>"&"*")

Example 13 - greater than or equal to


value from cell
You want to count cells where value is greater than or equal to value from cell C12.
Cells are in C column.
The formula is =COUNTIF(C2:C10,">="&C12)

Example 14 - greater than value from


cell
You want to count cells where value is greater than value from cell C12. Cells are in C
column.
The formula is =COUNTIF(C2:C10,">"&C12)

How the COUNTIF Function Works

How the COUNTIF Function Works


Related Tutorial: Text only version - Excel COUNTIF Function
The COUNTIF function combines the IF function and COUNT function in Excel. This
combination allows you to count the number of times specific data is found in a selected
group of cells.
The IF portion of the function determines what data meets the specified criteria and the
COUNT part does the counting.
COUNTIF Function Step by Step Tutorial
This tutorial uses a set of data records and the COUNTIF function to find the number of
Sales Reps who have more than 250 orders for the year.
Following the steps in the tutorial topics below walks you through creating and using
the COUNTIF function seen in the image above to count the number of sales reps with
more than 250 orders.

Entering the Tutorial Data

Entering the Tutorial Data


The first step to using the COUNTIF function in Excel is to enter the data.
Enter the data into cells C1 to E11 of an Excel worksheet as seen in the image above.

The COUNTIF function and the search criteria (greater than 250 orders) will be added
to row 12 below the data.
Note: The tutorial instructions do not include formatting steps for the worksheet.
This will not interfere with completing the tutorial. Your worksheet will look different
than the example shown, but the COUNTIF function will give you the same results.

The COUNTIF Function's Syntax

The COUNTIF Function's Syntax


In Excel, a function's syntax refers to the layout of the function and includes the
function's name, brackets, and arguments.
The syntax for the COUNTIF function is:
= COUNTIF ( Range, Criteria )

The COUNTIF Function's Arguments


The function's arguments tell the function what condition we are testing for and
what rangeof data to count when the condition is met.
Range - the group of cells the function is to search.
Criteria - this value is compared with the data in the Range cells. If a match is found
then the cell in the Range is counted. Actual data or the cell reference to the data can
be entered for this argument.

Starting the COUNTIF Function

Opening the COUNTIF Function Dialog Box


Although it is possible to just type the COUNTIF function into a cell in a worksheet,
many people find it easier to use the function's dialog box to enter the function.
Tutorial Steps
For help with these instructions, see the image above.
1.

2.

3.

Click on cell E12 to make it the active cell. This is where we will enter the
COUNTIF function.

Click on the Formulas tab of the ribbon.

Choose More Functions > Statistical from the ribbon to open the function
drop down list.

4.
Click on COUNTIF in the list to bring up the COUNTIF function's dialog box.
The data that we enter into the two blank rows in the dialog box will form
the arguments of the COUNTIF function.
These arguments tell the function what condition we are testing for and what cells to
count when the condition is met.

Entering the Range Argument

Entering the Range Argument


In this tutorial we want to find the number of Sales Reps who sold more than 250
orders for the year.
The Range argument tells the COUNTIF function which group of cells to search when
trying to find the specified criteria of " > 250 ".
Tutorial Steps
For help with these instructions, click on the image above.
1.
In the dialog box, click on the Range line.

2.

Drag select cells E3 to E9 on the worksheet to enter these cell references as the
range to be searched by the function.

3.
4.

Leave the dialog box open for the next step in the tutorial.

Entering the Criteria Argument

5.

Entering the Criteria Argument


The Criteria argument tells COUNTIF what data it should try to find in
the Range argument.
Although actual data - such as text or numbers like " > 250 " can be entered into
the dialog box for this argument it is usually best to enter a cell reference into
the dialog box, such as D12 and then enter the data we want to match into that cell in
the worksheet.
Tutorial Steps
For help with these instructions, click on the image above.
1.

2.

3.

4.

Click on the Criteria line in the dialog box.

Click on cell D12 to enter that cell reference. The function will search the range
selected in the previous step for data that matches whatever data is entered into
this cell.

Click OK to close the dialog box and complete the COUNTIF function.

An answer of zero should appear in cell E12 - the cell where we entered the
function - because we have not yet added the data to the Criteria field (D12).

Adding the Search Criteria

Adding the Search Criteria


The last step in the tutorial is to add the criteria we want the function to match.
In this case we want the number of Sales Reps with more than 250 orders for the year.
To do this we enter > 250 into D12 - the cell identified in the function as containing the
criteriaargument.
Tutorial Steps
For help with these instructions, see the image above.
1.
In cell D12 type > 250 and press the Enter key on the keyboard.

2.

3.

The number 4 should appear in cell E12.

The criterion of " > 250 " is met in four cells in column E: E4, E5, E8, E9.
Therefore these are the only cells counted by the function.

4.

When you click on cell E12, the complete function


=COUNTIF (E3:E9, D12) appears in the formula bar above the worksheet.

COUNTIF
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

Data

Data

apples

32

oranges

54

peaches

75

apples

86

Formula

Description (result)

=COUNTIF(A2:A5,"apples")

Number of cells with apples in the first column abov

=COUNTIF(A2:A5,A4)

Number of cells with peaches in the first column abo

=COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2)

Number of cells with oranges or apples in the first co


above (3)

=COUNTIF(B2:B5,">55")

Number of cells with a value greater than 55 in the s


column above (2)

=COUNTIF(B2:B5,"<>"&B4)

Number of cells with a value not equal to 75 in the s


column above (2)

=COUNTIF(B2:B5,">=32")COUNTIF(B2:B5,">85")

Number of cells with a value greater than or equal to


less than or equal to 85 in the second column above

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

Data

Data

apples

Yes

oranges

NO

peaches

No

apples

YeS

Formula

Description (result)

=COUNTIF(A2:A7,"*es")

Number of cells ending with the letters "es" in the first


above (4)

=COUNTIF(A2:A7,"?????es")

Number of cells ending with the letters "les" and havin


exactly 7 letters in the first column above (2)

=COUNTIF(A2:A7,"*")

Number of cells containing text in the first column abo

=COUNTIF(A2:A7,"<>"&"*")

Number of cells not containing text in the first column


(2)

=COUNTIF(B2:B7,"No") / ROWS(B2:B7)

The average number of No votes including blank cells


second column above formatted as a percentage with n

6
7

decimal places (33%)


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

The average number of Yes votes excluding blank cells


second column above formatted as a percentage with n
decimal places (50%)

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.

Excel COUNTIFS: A Step by Step Tutorial on How to Use


COUNTIFS in your Worksheets
With the launch of Microsoft 365 includingcloud services and the
new lowered-priced subscription options, Microsoft sales are
booming again and with over one billion installations of Microsoft
Office, proper training in the Microsoft suite of applications has
become essential. For a great overview of what Office 2013 has to
offer, sign up for theOffice 2013 For Dummies Video
Training, Deluxe Edition course from Udemytoday and get up
to speed with the new functionalities offered by Office 2013.
This tutorial is designed as a step by step guide on how to use the
COUNTIFS function in your worksheets and spreadsheets. We
have set up a worksheet for the purposes of this tutorial. The
worksheet contains sales data from a fictitious company including
customer names, salespersons name, the type of item sold, the
units sold and the total sales value per sale. Our worksheet for the
purposes of this tutorial looks like this:

The COUNTIFS function is very similar to the COUNTIF function.


For a step by step tutorial on how to use the COUNTIF function,
you can read: An Excel COUNTIF Tutorial to Show You How
to Use COUNTIF in your spreadsheets on the Udemy blog.
Lets see how we can use the COUNTIFS function in our worksheet
to extract the sales data we require.

How to use Excel Functions


Excel allows you to access the built-in functions by typing
the function namewithin the cell where you want the answer to
appear, or you can use the formulas tab to access the built-in
functions and then select the function you want to use from the
formula tab. For the purposes of this tutorial, we will use the
function from the formulas tab to show you how to enter function

arguments via the function wizard. Sign up for the Excel 2013:
Introducing Excel course today to learn to use the built-in
functions offered by Excel.
To use a formula or function in Excel, you need to know how the
function works and what the function does. For an article on
functions, you can read Excel Tutorial: An In-Depth Guide to
Working with your Data, Building Formulas, and Using
Functions available from the Udemy blog.
The COUNTIFS function uses parameters you enter in the function
to count the number of occurrences of data that meet your specific
requirements within the range of data you specify.

Using COUNTIFS to Calculate Jacks


Sales on a Given Day
Our first example will show you how to find out how many sales
Jack made on a specific date. Assume we need to find out how
many sales Jack made on the 7th of February.
To count how many sales Jack made, we need to access the
COUNTIFS function and use it to count the number of sales for
February 7th and also how many of those sales were made by Jack.
To create the function, click the target cell you want the answer to
show in and then click the formulas tab and then select the

COUNTIFS function from the More Functions, Statistical


menu.
You need to select the Date range for the first criteria so that Excel
searches and counts the number of date occurrences within that
range and then you need to set the criteria to the date you want to
search for. In this case we set our date range as =B10 because B10
contains the value of the date we want to search for.
You also need to select the range that contains the salespersons
name and then set the criteria to search for as Jack, so that we
count the number of sales made on the 7th of February by Jack.

The result of the above COUNTIFS formula will be 1. You can see
from the data that Jack made only one sale on the 7th:

Use COUNTIFS to Count how many


Items were sold between two dates
In our next example, we will create a few cells to allow us to quickly
search for sales for a specific item between two dates. We have
created named ranges for different columns of data. We called the
Date column dates, we named the Salesperson column
Salespersons, and we named the Unit type column Types. For
an article on cell references and how to create named ranges, you
can readExcel Cell References and How to Use Them in
Your Worksheets and Formulas on the Udemy blog and for a
course on how to create named ranges and how to get the best from
your Excel, sign up for Use Excel Like A Pro. Fast from Udemy.
Here are the cells we have added to our worksheet:

We can now use these cells in our COUNTIFS formula to quickly


and easy count data within our worksheet.
To create the COUNTIFS formula, select the COUNTIFS formula
from the formulas tab and then fill it in with the following data:

Because we are working with dates, you need to refer to the


absolute reference of the two date cells we are using for our search.
For an advanced course on Excel, sign up for the Microsoft Excel
2013 Advanced Online Excel Training Course from Udemy.

The dates refers to the named range we created for our dates and
the Types refers to the named range we created for our sale types.
By adding these fields, searches are simpler in future. All you need
to do is change the start and end dates and change the type to see
the sales of a particular item between two dates.
This is what the result of the above COUNTIFS function will look
like:

For an advanced course that will teach you to harness the power of
Excel function and formulas in your spreadsheets, sign up for the
Mastering Excel with MS-2007, 2010, 2013 course available
from Udemy today.

FREE EXCEL VIDEO TRAINING/TUTORING > TRADING


ADD-INS FOR EXCEL > CONVERT DATABASES
IF YOU ARE USING 2007

OR ABOVE,

USE COUNTIFS. FREE EXCEL HELP

There are many times that it become necessary to COUNT cells based on multiple
criteria. The examples below will show you 3 ways that this can be done. However,
often themost efficient method is to use a PIVOT TABLE If you are not familiar
with Pivot Tables, I cannot stress enough how much easier spreadsheet life becomes
once you are!
If you are not already aware, the Excel COUNTIF formula/function can only check to see
if specified cells meet one condition, e.g.
COUNTIF Syntax
=countif(range,criteria)
=COUNTIF(A1:A20,">20")
Which would COUNT all numeric cells in the range A1:A20 where values were greater
than 20.
Note the criteria argument is in the form of a number, expression, or text that defines
which cells will be counted. For example, criteria can be expressed as 20, "20", "=20",
">20", "North", "N*".
=COUNTIF($A$1:$A$20,20),

=COUNTIF($A$1:$A$20,">20"),

=COUNTIF($A$1:$A$20,"North"), =COUNTIF($A$1:$A$20,"N*")
Ok, so if we need to count a range of cells where corresponding cells (on the same row
but different column) meet 1, or more conditions we can no longer use the COUNTIF.
The other formulas we can use, in order of their efficiency, are

1)

DCOUNT

2)

&

DCOUNTA DOWNLOAD

SUM

as

ADVANCED

EXAMPLES

an ARRAY

OF

DCOUNT
FORMULA

3) COUNT with and IF function nested and entered as an ARRAY FORMULA .


DCOUNT will count only numeric cells where the cells, or corresponding cells meet a
specified

criteria.

DCOUNTA will count all cells (Text or numeric) where the cells, or corresponding cells
meet a specified criteria.
For all examples I will use the data as shown below. Where A2:E25 has been
named: DataTable

DCOUNT
Count the numbers in a column of a list, or database, that match criteria you specify.
For example;=DCOUNT(DataTable,B2,Criteria)Would Count all cells in B2:B25 that
meet the criteria is the named range:Criteria (shown below)

The top row of the range: Criteria has exact copies of the headings in the range
DataTable . The reference to cell B2 is telling the DCOUNT to count the numbers
in B2:B25 that meet the criteria. We could replace the reference to B2 with the text
"Quantity", or the number 2 as the "Quantity" column is the second column in the
table.
The criteria text "Bourbon" and "Vodka", under the criteria table heading "Description",
tells DCOUNT that either "Bourbon" OR "Vodka" is a match. The same principle is used
for the "Alcohol Content", i.e. "High" OR "Low". This is then seen by DCOUNT as an OR
condition.
Note the repeat of the date under "Use By Date". This is needed when using more than
2 rows as the criteria as a blank cell is seen as a wildcard character. If we wanted to
count only data that lies between 2 dates, we would need have 2 "Use By Date"
headings in our Criteria range and use: >7-Apr-2005 below one of these headings and
<7-Jun-2005 under another. This is then seen by DCOUNT as an AND condition.
DOWNLOAD ADVANCED EXAMPLES OF DCOUNT
DCOUNTA
If we changed the above DCOUNT example to:
=DCOUNT(DataTable,A2,Criteria)
We would always get a result of 0 (zero) regardless of the criteria being met, or not.
This is because DCOUNT will only ever count all numeric cells and there are none in
column A under the "Description" field.

To get a count of these cells, we would need to use the DCOUNTA function which would
count all cells, text or numeric, where the criteria is being met. That is;
=DCOUNTA(DataTable,A2,Criteria)
SUM as an array formula
Normally, the SUM function will add all numeric cells in a specified range. However,
when used as an array formula with criteria used, it will give us a count instead of a
sum.

See

below

example=SUM((A2:A25="Vodka")*(C2:C25>VALUE("7-Apr-

2005"))*(E2:E25="High"))+SUM((A2:A25="Bourbon")*(C2:C25>VALUE("7-Apr2005"))*(E2:E25="Low"))
As with the DCOUNTA example, the above array entered (Ctrl+Shift+Enter) SUM
example would count all rows where the "Use By Date" is greater than 7-Apr-2005, the
"Description" is either "Vodka" OR "Bourbon" and the "Alcohol Content" is "High" OR
"Low".
The reason it gives a count is because each check is returned as TRUE (has a value of
1) or FALSE (has a value of 0). So, in the above example, the third row check would
actually look like;=SUM((0)*(0)*(1))+SUM((1)*(1)*(1))As you can see, unless all 3
criteria are met in at least one of the Sum functions, the result will always be 0
(FALSE). To read about this in detail, see our April edition of our free EXCEL NEWSLETTER
COUNT and IF
=COUNT(IF(A2:A25="Bourbon",IF(C2:C25>VALUE("7-Apr2005"),IF(E2:E25="Low",B2:B25))))
+COUNT(IF(A2:A25="Vodka",IF(C2:C25>VALUE("7-Apr2005"),IF(E2:E25="High",B2:B25))))
The above, does the same as the array SUM example and must be entered by
pushing Ctrl+Shift+Enter. Note we have told the COUNT to count all cells in B2:B25

where the criteria is met. In other words, count all "Quantity" cells where the rest of the
specified rows of the "Description", "Use By Date" and "Alcohol Content" meet the
specified criteria
It is important to know that using the array entered COUNT and IF, or the SUM as
an ARRAY FORMULA over a large number of cells will cause a noticeable slow down in
Excel's recalculation time. The DCOUNT & DCOUNTA are

far more efficient in this

regard. However, as stated at the very Start , a PIVOT TABLE is better still when done
correctly.

www.free-training-tutorial.com/statistical-functions.html