I saw an solution where someone was using a range as the criteria for COUNTIF and while trying to understand it better I found some really odd things happening and hoping someone could explain to me what is going on. Here is the setup of the excel.
Name,,Name
Excitebike,,Excitebike
RC Pro Am,,Super Mario Brothers
Punch Out,,Duck Hunt
Super Mario Brothers
Duck Hunt
Hopefully you can use the above to copy and paste it in. In column A there is a list of names and in column C there is a list of some of the names. In cell E1 there is a formula:
=COUNTIF($C$2:C4,$A$2:$A$6)
Then in cell E2 there is the exact same formula.
=COUNTIF($C$2:C4,$A$2:$A$6)
Here is a screen shot so you can see the formulas are identical:
So cell E1 and E2 have the exact same formula but are giving me a different result. As you can see in the first screen shot cell E1 gives a result of 0 while E2 gives a result of 1. Then if I make cell E1 into an array formula it gives a result of 1.
Why would the exact same formula in two different cells give a different result and why when changing cell E1 to an array formula would it change the result? I am using Excel 2016.
UPDATED: Additional questions.
When passing in a array into COUNTIF does it check each element in the range against each element in the criteria or does it just check row in the range against the corresponding row in the criteria?
Even when I put them in the same order, I cannot get the COUNTIF to return a number greater then 1. I would expect if the first 3 match the COUNTIF should return 3 but it is returning 1 for me. Please see below:
While rows 2, 3 and 4 match it is still giving an answer of 1.
Punch Out
in C4 and you will not get 2 in either till you enter them in as arrays. – Scott CranerA1:A6
to just be numbers 1 through 6. Then changeE1
to just=$A$1:$A$6
and it will return1
. Drag that formula down and it will return2
,3
,4
,5
, and6
, for each respective row. – JNevill=COUNTIF(A2:A6,C2:C6)
inE2
it will be evaluated as if it was=COUNTIF(A2:A6,C2)
. UnlessA2:A6
contains the value found inC2
more than once, you will only get1
back as an answer. The first parameter inCountif()
is supposed to be a range, so you are all good there. It's that second parameter that gets evaluated as a single cell based on the range entered as the second parameter and the row in which the formula resides. That's where the strange behavior is happening. – JNevill=SUM(COUNTIF($C$2:C4,$A$2:$A$6))
– Scott Craner