Samuel GIFFARD
Samuel GIFFARD

Reputation: 842

Count if a cell has the same value as another one in the same column

I'm trying to find a formula to count the number of times, in a given row, a cell has the same value as another one in another row (same column)

Basically, I have something like

-----------------
| 1 | S | M | M |
-----------------
| 2 | M | M | M |
-----------------
| 0 | S | M | S |
-----------------
| 1 | S | M | M |
-----------------
| 3 | M | S | M |
-----------------
....
|   | M | S | M |  // <--- the reference row
-----------------

The numbers 1, 2, 0, 1, 3 are to be calculated with the formula. 1 -> Only one matches the reference row, which is the last M 2 -> There are two matches, first cell and last cell

Etc...

I have tried stuff like =COUNTIF(E5:Z5, "="&INDIRECT(ADDRESS(21,COLUMN(),2))). But the COLUMN() has the value of the column where this is written and not the value of the column that is being evaluated in the COUNTIF().

If a general way, I can't seem to find a way to refer to the cell being currently evaluated in the COUNTIF.

May someone has the answer :).

Regards

Upvotes: 0

Views: 1214

Answers (1)

Tom Sharpe
Tom Sharpe

Reputation: 34230

Should be easier with Sumproduct:

=SUMPRODUCT((B1:Z1=B$21:Z$21)*(B1:Z1<>""))

enter image description here

Upvotes: 2

Related Questions