Formula that counts occurrences in two columns where row values are equal

travellerva

New Member
Joined
Mar 31, 2012
Messages
47
Office Version
  1. 365
Platform
  1. MacOS
I'm trying to find a formula that provides a count of the number of times in two columns that the values in corresponding rows are equal. I've tried various versions of COUNTIF without success. I realise this could be done by creating a "shadow" column that flags each row that's equal, then counting that column but I don't want to add a third column - even hidden. I also don't want to do it as a macro. Many thanks for all ideas.

[TABLE="width: 195"]
<colgroup><col><col span="2"></colgroup><tbody>[TR]
[TD="colspan: 3"]Problem: What is the formula in A1 that will give the result of the number of occasions the values in a row are equal?[/TD]
[/TR]
[TR]
[TD="colspan: 2"](2 in the example below)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]alpha[/TD]
[TD]45[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]beta[/TD]
[TD]36[/TD]
[TD]36[/TD]
[/TR]
[TR]
[TD]gamma[/TD]
[TD]14[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]delta[/TD]
[TD]66[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]epsilon[/TD]
[TD]78[/TD]
[TD]78[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi,

Is the First column ( alpha, beta, etc. ) a factor for the count ?

Edit, since I already worked it up even thou it's also posted below, I'll post it anyway, assuming your 1st column is Not a factor:


Book1
ABCD
12alpha4523
2beta3636
3gamma1425
4delta6645
5epsilon7878
Sheet551
Cell Formulas
RangeFormula
A1=SUMPRODUCT(--(C1:C5=D1:D5))
 
Last edited:
Upvote 0
Many thanks. No, the first column is not a factor so your solution works fine.

Great help!
 
Upvote 0
Actually - I was too fast to reply! The formula you suggest actually yields twice the correct result. The easy way out is just =SUMPRODUCT(--(B2:B6=C2:C6))/2
 
Upvote 0
Nah - forget that. Your formula is absolutely correct. In my application of it I had several empty cells in the range that were counted as equal. Please ignore my last reply.
 
Last edited:
Upvote 0
If you might have Blanks within your range, you can use one of these instead:


Book1
ABCD
13alpha4523
23beta3636
3
4gamma1425
5
6delta6645
79999
8epsilon7878
Sheet551
Cell Formulas
RangeFormula
A1=SUMPRODUCT((C1:C8=D1:D8)*(C1:D8<>""))/2
A2=SUMPRODUCT((C1:C8=D1:D8)*(C1:C8<>"")*(D1:D8<>""))
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top