Count how many times in total two values appear together in a row for all the rows

Dainer

New Member
Joined
Dec 25, 2017
Messages
5
Hello

The title may be confusing to understand but here is an example of what I need to achieve.

[TABLE="class: grid, width: 150"]
<tbody>[TR]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[/TR]
</tbody>[/TABLE]

I would like to know a formula, that counts the rows where number "5" appears together with number "6" in the entire table and outputs how many of those rows are in total.

On the example table we can see that "5" and "6" appear together in 4 rows, so output = 4

Thank you in advance
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If "5 and 6 appear together" means "5 and 6 in this very order in adjacent cells in the same row," then try the following array formula:

=SUM(--(MMULT((A1:E5=5)*(B1:F5=6),{1;1;1;1;1})>0))

If "5 and 6 appear together" means "5 and 6 anywhere in the same row," then try the following array formula:

=SUM((MMULT(--(A1:E5=5),{1;1;1;1;1})>0)*(MMULT(--(A1:E5=6),{1;1;1;1;1})>0))

Note: these array formulas should be entered using Ctrl+Shift+Enter, not just Enter.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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