You are on page 1of 27

EXCEL COUNTIF EXAMPLES 09/15/2015

Excel COUNTIF Examples


Excel COUNTIF Function

Purpose:
Count cells that match criteria
Return value:
A number representing cells counted.
Syntax:
=COUNTIF (range, criteria)
Parameter list:

 range - The range of cells to count.


 criteria - The criteria that controls which cells should be counted.

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Count cells between two numbers

=COUNTIFS(range,">=X",range,"<=Y")

If you need to count the number of cells that contain values between two numbers in a range of
cells, you can do so with a formula that uses the COUNTIFS function. In the generic form of the
formula (above) range represents a range of cells that contain numbers, X represents the lower
boundary, and Y represents the upper boundary of the numbers you want to count.

In the example, the active cell contains this formula:

=COUNTIFS(C4:C10,">=80",C4:C10,"<=90")

How the formula works:

The COUNIFS function is built to count cells that meet multiple criteria. In this case, because we
supply the same range for two criteria, each cell in the range must meet both criteria in order to
be counted.

Using COUNTIF instead

If you have an older version of Excel that doesn't have the COUNTIFS function, you can use the
COUNTIF function instead like this:

=COUNTIF(range,">X")-COUNTIF(range,">Y")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

The first COUNTIF counts the number of cells in a range that greater than or equal to X (which
by definition also includes values greater than Y, since Y is greater than X). The second
COUNTIF counts the number of cells with values greater than Y. This second number is then
subtracted from the first number, which yields the final result - the number of cells that contain
values between X and Y.

Making the criteria variable

If you want to use a value in another cell as part of the criteria, use the ampersand (&) character
to concatenate like this:

=COUNTIF(rng,">"&a1)

If the value in cell a1 is "5", the criteria will be ">5" after concatenation.

Count cells equal to

=COUNTIF(rng,value)

If you need to count the number of cells that contain a certain value, you can do so with a
formula that uses the COUNTIF function. In the generic form of the formula (above) rng
represents a range of cells, and value represents the value you want to count.

In the example, the active cell contains this formula:

=COUNTIF(C4:C10,"yes")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Here's how the formula works:

COUNTIF counts the number of cells in a range that match the supplied criteria. In this case, the
criteria is supplied as the value "yes" (text values need to be enclosed in quotes). COUNTIF then
returns the number of cells that contain "yes"

COUNTIF is not not case sensitive. In the example, the word "Yes" in any combination of upper
and lower case letters will be counted.

If you are counting cells that contain a numeric value, there is no need to add quotes around the
numbers. For example, if in the above example you wanted to count cells that contain zero, the
formula is:

=COUNTIF(C4:C10,0)

If you want to use a value in another cell as the criteria, just drop it into the formula like so

=COUNTIF(rng,a1)

This will work with both numeric and text values.

Count cells equal to either

=COUNTIF(rng,value1) + COUNTIF(rng,value2)

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

If you need to count the number of cells that are equal to either one value or another, you can do
so with a formula that uses the COUNTIF function twice. In the generic form of the formula
(above) rng represents a range of cells and value1 and value2 represent the two values you want
to count.

In the example, the active cell contains this formula:

=COUNTIF(B4:B9,"apples")+COUNTIF(B4:B9,"pears")

Here's how the formula works:

COUNTIF counts the number of cells in a range that match the supplied criteria. In this case, the
criteria for the first COUNTIF is "apples" and the criteria for the second COUNTIF is "pears".
The first COUNTIF returns the count of cells in B4:B9 equal to "apples". The second COUNTIF
returns the count of cells in B4:B9 equal to "pears". These two counts are added together and the
sum is returned as the result of the formula.

Note that text values in the criteria for COUNTIF need to be enclosed in quotes (""). Also note
that COUNTIF is not not case sensitive. In the example, the words "apples" and "pears" in any
combination of upper and lower case letters will be counted.

If you are counting cells that contain a numeric value, there is no need to add quotes around the
numbers. For example, if in the above example you wanted to count cells that contain zero, or 1
the formula is:

=COUNTIF(rng,0) + COUNTIF(rng,1)

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Count cells greater than

=COUNTIF(rng,">X")

If you need to count the number of cells that contain values greater than a particular number, you
can use the COUNTIF function. In the generic form of the formula (above) rng represents a
range of cells that contain numbers, and X represents the boundary above which you want to
count.

In the example, the active cell contains this formula:

=COUNTIF(C4:C10,">90")

Here's how the formula works:

COUNTIF counts the number of cells in the range that contain numeric values greater than X,
and returns the result as a number.

If you want to count cells that are greater than or equal to 90, use:

=COUNTIF(C4:C10,">=90")

If you want to use a value in another cell as part of the criteria, use the ampersand (&) character
to concatenate like this:

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

=COUNTIF(rng,">"&a1)

If the value in cell a1 is "70", the criteria will be ">70" after concatenation.

Count cells less than

=COUNTIF(rng,"<X")

If you need to count the number of cells that contain values less than a particular number, you
can use the COUNTIF function. In the generic form of the formula (above) rng represents a
range of cells that contain numbers, and X represents the boundary below which you want to
count.

In the example, the active cell contains this formula:

=COUNTIF(C4:C10,"<80")

Here's how the formula works:

COUNTIF counts the number of cells in the range that contain numeric values less than X and
returns the result as a number.

If you want to count cells that are less than or equal to 80, use:

=COUNTIF(C4:C10,"<=80")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

If you want to use a value in another cell as part of the criteria, use the ampersand (&) character
to concatenate like this:

=COUNTIF(rng,"<"&a1)

If the value in cell a1 is "100", the criteria will be "<100" after concatenation.

Count cells not equal to

=COUNTIF(rng,"<>X")

If you need to count the number of cells that contain values not equal to a particular value, you
can use the COUNTIF function. In the generic form of the formula (above) rng represents a
range of cells, and X represents the value you don't want to count. All other values will be
counted.

In the example, the active cell contains this formula:

=COUNTIF(D4:D10,"<>Complete")

How the formula works:

COUNTIF counts the number of cells in the range that meet criteria you supply.

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

In the example, we use "<>" (the logical operator for "does not equal") to count cells in the range
D4:D10 that don't equal "complete". COUNTIF returns the count as a result.

COUNTIF is not case-sensitive. In this example, the word "complete" can appear in any
combination of uppercase / lowercase letters and will not be counted.

If you want to use a value in another cell as part of the criteria, use the ampersand (&) character
to concatenate like this:

=COUNTIF(rng,"<>"&a1)

If the value in cell a1 is "100", the criteria will be "<>100" after concatenation, and COUNTIF
will count cells not equal to 100.

Count cells that begin with

=COUNTIF(rng,"txt*")

If you need to count the number of cells begin with certain text, you can easily do so with the
COUNTIF function. In the generic form of the formula (above) rng is a range of cells, txt
represents the text that cells should begin with, and "*" is a wildcard matching any number of
characters.

In the example, the active cell contains this formula:

=COUNTIF(B4:B11,"app*")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Here's how the formula works:

COUNTIF counts the number of cells in the range that begin with txt by matching the content of
each cell against the pattern "txt*", which is supplied as the criteria. The "*" symbol (the
asterisk) is a wildcard in Excel that means "match any number of characters". The count of cells
that match this pattern is returned as a number.

Count cells that contain five characters

=COUNTIF(rng,"?????")

If you need to count the number of cells that contain a certain number of characters text, you can
easily do so with the COUNTIF function. In the generic form of the formula (above), rng is a
range of cells, and "?" is a wildcard matching any single character.

In the example, the active cell contains this formula:

=COUNTIF(B4:B9,"?????")

Here's how the formula works:

COUNTIF counts the number of cells in the range that contain five characters by matching the
content of each cell against the pattern "?????", which is supplied as the criteria for COUNTIF.
The "?" symbol is a wildcard in Excel that means "match any single character", so this pattern

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

will count cells that contains any five characters. The count of cells that match this pattern is
returned as a number which, in the example, is the number 2.

Count cells that contain negative numbers

=COUNTIF(rng,"<0")

If you need to count the number of cells that contain negative numbers in a range of cells, you
can do so with a formula that uses the COUNTIF function. In the generic form of the formula
(above) rng represents a range of cells that contain numbers.

In the example, the active cell contains this formula:

=COUNTIF(B2:B6,"<0")

Here's how the formula works:

COUNTIF counts the number of cells in a range that match the supplied criteria. In this case, the
criteria is supplied as "<0", which is evaluated as "values less than zero". The total count of all
cells in the range that meet this criteria is returned by the function.

You can easily adjust this formula to count cells based on other criteria. For example, to count all
cells with a value less -10, use this formula:

=COUNTIF(rng,"<-10")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

If you want to use a value in another cell as part of the criteria, use the ampersand (&) character
to concatenate like this:

=COUNTIF(rng,"<"&a1)

If the value in cell a1 is "-5", the criteria will be "<-5" after concatenation.

Count cells that contain positive numbers

=COUNTIF(rng,">0")

If you need to count positive numbers in a range of cells, you can do with a formula that uses
COUNTIF. In the generic form of the formula (above) rng represents a range of cells that contain
numbers.

In the example, the active cell contains this formula:

=COUNTIF(B2:B6,">0")

Here's how the formula works:

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

COUNTIF counts the number of cells in a range that match the supplied criteria. In this case, the
criteria is supplied as ">0", which is evaluated as "values greater than zero". The total count of
all cells in the range that meet this criteria is returned by the function.

You can easily adjust this formula to count cells based on other criteria. For example, to count all
cells with a value greater than or equal to 100, use this formula:

=COUNTIF(rng,">=100")

Count cells that contain specific text

=COUNTIF(rng,"*txt*")

If you need to count the number of cells that contain certain text, you can easily do so with the
COUNTIF function. In the generic form of the formula (above), rng is a range of cells, txt
represents the text that cells should contain, and "*" is a wildcard matching any number of
characters.

In the example, the active cell contains this formula:

=COUNTIF(B4:B11,"*a*")

How the formula works

COUNTIF counts the number of cells in the range that contain "a" by matching the content of
each cell against the pattern "*a*", which is supplied as the criteria. The "*" symbol (the
EXCEL COUNTIF EXAMPLES AMIR MANZOOR
EXCEL COUNTIF EXAMPLES 09/15/2015

asterisk) is a wildcard in Excel that means "match any number of characters", so this pattern will
count any cell that contains "a" in any position. The count of cells that match this pattern is
returned as a number.

You can easily adjust this formula to use the contents of another cell for the criteria. For
example, if A1 contains the text you want to match, use the formula:

=COUNTIF(rng,"*"&a1&"*")

Case-sensitive version

If you need a case-sensitive version, you can't use COUNTIF. Instead you can test each cell in
the range using a formula based on the FIND function and the ISNUMBER function, as
explained here.

FIND is case-sensitive, and you'll need to give it the range of cells and then use SUMPRODUCT
to count the results. The formula looks like this:

=SUMPRODUCT(--(ISNUMBER(FIND(text,rng))))

Where text is the text you are looking for, and rng is the range of cells you want to count.
There's no need to use wildcards, because FIND will return a number if text is found anywhere
in the cell.

Count cells that contain text

=COUNTIF(rng,"*")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

If you need to count the number of cells that contain text, you can do so with the COUNTIF
function and a wildcard. In the generic form of the formula (above), rng is a range of cells, and
"*" is a wildcard matching any number of characters.

Click here to count cells that contain specific text

In the example, the active cell contains this formula:

=COUNTIF(B4:B8,"*")

Here's how the formula works:

COUNTIF counts the number of cells that match the supplied criteria. In this case, the criteria is
supplied as the wildcard character "*" which matches any number of text characters.

A few notes:

 The logical values TRUE and FALSE are not counted as text
 Numbers are not counted by "*" unless they are entered as text
 A blank cell that begins with an apostrophe (') will be counted.

You can also use SUMPRODUCT to count text values along with the function ISTEXT like so:

=SUMPRODUCT(--ISTEXT(rng))

The double hyphen (called a double unary) coerces the result of ISTEXT from a logical value of
TRUE or FALSE, to 1's and 0's. SUMPRODUCT then sums these values together to get a result.

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Count cells that do not contain

=COUNTIF(rng,"<>*txt*")

If you need to count the number of cells that do not contain certain text, you can easily do so
with the COUNTIF function. In the generic form of the formula (above), rng is a range of cells,
txt represents the text that cells should not contain, and "*" is a wildcard matching any number of
characters.

In the example, the active cell contains this formula:

=COUNTIF(B4:B11,"<>*a*")

Here's how the formula works:

COUNTIF counts the number of cells in the range that do not contain "a" by matching the
content of each cell against the pattern "<>*a*", which is supplied as the criteria. The "*" symbol
(the asterisk) is a wildcard in Excel that means "match any number of characters" and "<>"
means "does not equal", so this pattern will count any cell that does not contain "a" in any
position. The count of cells that match this pattern is returned as a number.

You can easily adjust this formula to use the contents of another cell that contains the text you do
not want to count. The generic form of the formula looks like this:

=COUNTIF(rng,"<>*"&a1&"*")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Count cells that end with

=COUNTIF(rng,"*txt")

If you need to count the number of cells end with certain text, you can easily do so with the
COUNTIF function. In the generic form of the formula (above) txt represents the text that cells
should end with, and "*" is a wildcard matching any number of characters.

In the example, cell F4 contains this formula:

=COUNTIF(B4:B11,"*r")

How the formula works

COUNTIF counts the number of cells in the range that begin end with "r" by matching the
content of each cell against the pattern "*r", which is supplied as the criteria. The "*" symbol
(the asterisk) is a wildcard in Excel that means "match any number of characters". The count of
cells that match this pattern is returned as a number.

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Count unique numeric values in a range

=SUMPRODUCT(--(FREQUENCY(data,data)>0))

If you need to count unique numeric values in a range, you can use a formula that uses the
FREQUENCY function together with the SUMPRODUCT function.

For example, assume you have a list of employee numbers together with hours worked on
"Project X", and you want know how many employees worked on that project. Looking at the
data, you can see that the same employee numbers appear more than once, so what you want is a
count of the unique employee numbers that appear in the list.

The employee numbers appear in the range B3:B12. To get a count of unique numbers, you can
use the following formula:

=SUMPRODUCT(--(FREQUENCY(B3:B12,B3:B12)>0))

How this formula works

The FREQUENCY function returns an array of values that correspond to "bins". In this case, we
are supplying the same set of numbers for both the data array and bins array.

The result is that FREQUENCY returns an array of values that indicate the count that each value
in the data array appears. FREQUENCY has a special feature that automatically returns zero for
any numbers that appear more than once in the data array, so the return array looks like this:

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

{3;0;0;2;0;3;0;0;2;0;0}

Next, each of these values is tested to be greater than zero. The result looks like this:

{TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE}

Now each TRUE in the list represents a number that appears more than once. However,
SUMPRODUCT doesn't handle text or logical values, so we need to coerce the values into 1 or
zero. This is done with the double-hyphen (double-unary). The result is:

{1;0;0;1;0;1;0;0;1;0;0}

Finally, SUMPRODUCT simply adds these values up and returns the total, which in this case is
4.

Using COUNTIF instead of FREQUENCY to count unique values

Another way to count unique numeric values is to use COUNTIF instead of FREQUENCY. This
is a much simpler formula, but beware that using COUNTIF on larger data sets to count unique
values can cause performance issues. The FREQUENCY-based formula, while more
complicated, calculates much faster.

Count unique values in a range

=SUMPRODUCT(1/COUNTIF(data,data))

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

If you need to count the number of unique values in a range of cells (named "data" in the
example below), you can use a formula that uses COUNTIF and SUMPRODUCT.

How the formula works

Working from the inside out, COUNTIF looks inside the data range and counts the number of
times that each individual value appears in data. The result is an array or numbers, that might
look something like this: {1,2,2,3,3,3}.

After COUNTIF is finished the results are used as a divisor with 1 as the numerator. Values that
appear in data once appear in the array as 1, but values that appear multiple times will appear as
fractional values that correspond to the mutliple. (i.e. a value that appears 5 times in data will
generate 5 items in the array with a value of 1/5 = .2).

Finally, the SUMPRODUCT function sums all values in the array and returns the result.

Handling blank cells

If data might contain blank cells, you need to adjust the formula as follows:

=SUMPRODUCT(1/COUNTIF(data,data&""))

The data&"" expression prevents zeros from ending up in the array in the case of blank cells.
This is important, because a zero in the divisor will throw a #DIV/0 error. This formula won't
throw an error when there are blank cells, but it will include blank cells in the count. If you want
to exclude blank cells in the count, use:

=SUMPRODUCT((data<>"")/COUNTIF(data,data&""))

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Highlight cells that begin with

=SEARCH("substring",A1)=1

Note: Excel contains many built-in "presets" for highlighting values with conditional formatting,
including a preset to highlight cells that begin with specific text. However, if you want more
flexibility, you can use your own formula, as explained in this article.

If you want to highlight cells that begin with certain text, you can use a simple formula that
returns TRUE when a cell starts with the text (substring) you specify.

For example, if you want to highlight any cells in the range B4:G12 that start with "mi", you can
use:

=SEARCH("mi",B4)=1

Note: with conditional formatting, it's important that the formula be entered relative to the
"active cell" in the selection, which is assumed to be B4 in this case.

How this formula works

When you use a formula to apply conditional formatting, the formula is evaluated relative to the
active cell in the selection at the time the rule is created. In this case, the rule is evaluated for
each cell in B4:G12, and B4 will change to the address of the cell being evaluated each time,
since it is entered as a relative address.

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

The formula itself uses the SEARCH function to match cells that begin with "mi". SEARCH
returns a number that indicates position when the text is found, and a #VALUE! error if not.
When SEARCH returns the number 1, we know that the cell value begins with "mi". The
formula returns TRUE when the position is 1 and FALSE for any other value (including errors).

With a named input cell

If you use a named range to name an input cell (i.e. name G2 "input"), you can simply for the
formula and make a much more flexible rule:

=SEARCH(input,B4)=1

Then when you change the value in "input", the conditional formatting will instantly be updated.

Case sensitive option

SEARCH is not case-sensitive, so if you need to check case as well, you can use the FIND
function instead:

=FIND(input,B4)=1

FIND works just like SEARCH, but matches case as well.

Highlight cells that end with

=COUNTIF(A1,"*text")

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Note: Excel contains many built-in rules for highlighting values with conditional formatting,
including a rule to highlight cells that end with specific text. However, if you want more
flexibility, you can use your own formula, as explained in this article.

If you want to highlight cells that end with certain text, you can use a simple formula based on
the COUNTIF function. For example, if you want to highlight states in the range B4:G12 that
end with "ota", you can use:

=COUNTIF(B4,"*ota")

Note: with conditional formatting, it's important that the formula be entered relative to the
"active cell" in the selection, which is assumed to be B4 in this case.

How this formula works

When you use a formula to apply conditional formatting, the formula is evaluated relative to the
active cell in the selection at the time the rule is created. In this case, the rule is evaluated for
each cell in B4:G12, and the reference to B4 will change to the address of each cell being
evaluated, since it is a relative address.

The formula itself uses the COUNTIF function to "count" cells that end with "ota" using the
pattern "*ota" which uses a wildcard (*) to match any sequence of characters followed by "ota".
From a practical standpoint, we are only counting 1 cell each time, which means we are either
going to get back a 1 or a zero, which works perfectly for conditional formatting.

A simpler, more flexible rule using named ranges

By naming an input cell as a named range and referring to that name in the formula, you can
make the formula more powerful and flexible. For example, if you name G2 "input", you can
rewrite the formula like so:

=COUNTIF(B4,"*"&input)

This formula simply adds "*" to the beginning of whatever you put in the input cell. As a result,
the conditional formatting rule will respond instantly whenever that value is changed.

Case sensitive option

COUNTIF is not case-sensitive, so if you need to check case as well, you can use a more
complicated formula that relies on the RIGHT function together with EXACT:

=EXACT(RIGHT(A1,LEN(substring)),substring)

In this case, RIGHT extracts text from the right of each cell, and only the number of characters in
the substring you are looking for, which is supplied by LEN. Finally EXACT compares the

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

extracted text to the text you are looking for (the substring). EXACT is case-sensitive, so only
will return TRUE when all characters match exactly.

Highlight duplicate rows

=COUNTIFS(col_a,$A1,col_b,$B1,col_c,$C1)

Excel contains a built-in preset for highlighting duplicate values with conditional formatting, but
it only works at the cell level. If you want to highlight entire rows that are duplicates you'll need
to use your own formula, as explained below.

If you want to highlight duplicate rows in an unsorted set of data, and you don't want to add a
helper column, you can use a formula that uses the COUNTIFS function to count duplicated
values in each column of the data.

For example, if you have values in the cells B4:D11, and want to highlight entire duplicate rows,
you can use rather ugly formula:

=COUNTIFS($B$4:$B$11,$B4,$C$4:$C$11,$C4,$D$4:$D$11,$D4)>1

Named ranges for a cleaner syntax

The reason the above formula is so ugly is that we need to fully lock each column range, then
used a mixed reference to test each cell in each column. If you create named ranges for each
column in the data: col_a, col_b, and col_c, the formula can be written with a much cleaner
syntax:

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

=COUNTIFS(col_b,$B4,col_c,$C4,col_d,$D4)>1

With a helper column

If you don't mind adding a helper column to your data, you can simplify the conditional
formatting formula quite a bit. In a helper column, concatenate values from all columns. For
example, add a formula in column E that looks like this:

=B4&C4&D4

Then use the following formula in the conditional formatting rule:

=COUNTIF($E$4:$E$11,$E4)>1

This is a much simpler rule, and you can hide the helper column if you like.

How this formula works

In the formula, COUNTIFS counts the number of times each value in a cell appears in its
"parent" column. By definition, each value must appear at least once, so when the count > 1, the
value must be a duplicate. The references are carefully locked so the formula will return true
only when all 3 cells in a row appear more than once in their respective columns.

The helper column option "cheats" by combining all values in a row together in single cell using
concatenation. Then COUNTIF simply counts the number of times this concatenated value
appears in column D.

Another way

If you're using a version of Excel before 2007, or if you just prefer to use SUMPRODUCT
because you like it, you can also use this formula:

=SUMPRODUCT((col_b=$B4)*(col_c=$C4)*(col_d=$D4))>1

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

Highlight duplicate values

=COUNTIF(data,A1)>1

Note: Excel contains many built-in "presets" for highlighting values with conditional formatting,
including a preset to highlight duplicate values. However, if you want more flexibility, you can
highlight duplicates with your own formula, as explained in this article.

If you want to highlight cells that contain duplicates in a set of data, you can use a simple
formula that returns TRUE when a value appears more than once.

For example, if you want to highlight duplicates in the range B4:G11, you can use this formula:

=COUNTIF($B$4:$G$11,B4)>1

Note: with conditional formatting, it's important that the formula be entered relative to the
"active cell" in the selection, which is assumed to be B4 in this case.

How this formula works

COUNTIF simply counts the number of times each value appears in the range. When the count is
more than 1, the formula returns TRUE and triggers the rule.

When you use a formula to apply conditional formatting, the formula is evaluated relative to the
active cell in the selection at the time the rule is created. In this case, the range we are using in

EXCEL COUNTIF EXAMPLES AMIR MANZOOR


EXCEL COUNTIF EXAMPLES 09/15/2015

COUNTIF is locked with an absolute address, but B4 is fully relative. So, the rule is evaluated
for each cell in the range, with B4 changing and $B$4:$G$11 remaining unchanged.

A variable number of duplicates + named ranges

Instead of hard-coding the number 1 into the formula you can reference a cell to make the
number of duplicates variable.

You can extend this idea and make the formula easier to read by using named ranges. For
example, if you name G2 "dups", and the range B4:G11 "data", you can rewrite the formula like
so:

=COUNTIF(data,B4)>=dups

You can then change the value in G2 to anything you like and the conditional formatting rule
will respond instantly, highlighting cell that contain values greater than or equal to the number
you put in the named range "dups".

EXCEL COUNTIF EXAMPLES AMIR MANZOOR

You might also like