Count occurrences in a row with multiple criteria

mo70ss

New Member
Joined
Jun 14, 2020
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
I am struggling to write a formula that will count the number of times a given number has appeared with another given number. Each day there are 5 numbers drawn between 1 and 10. I need to know how times times lets say the number 1 and the number 2 have appeared in the same row.
Below is a sample of what it should look like. For example, the number 1 has appeared in the same row with the number 2 1 time. The number 5 has appeared in the same row with the number 6 3 different times.
Any help would be greatly appreciated!! Thank you in advance.

DrawDate#1#2#3#4#5#12345678910
1
6/1/2020​
12341011111
2
6/2/2020​
25679211111111
3
6/3/2020​
3457831121111
4
6/4/2020​
456894112211211
5
6/5/2020​
5678951123333
6113223
71113222
8123222
9113322
101111
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the MrExcel forums!

There's probably a better way, but this was my first idea and it worked:

Book1
ABCDEFGHIJKLMNOPQRS
1DrawDate#1#2#3#4#5#12345678910
216/1/20201234101 111000001
326/2/20202567921 11111011
436/3/202034578311 2101101
546/4/2020456894112 211211
656/5/20205678950112 33330
7601013 2230
87011132 220
980012322 20
10901013322 0
1110111100000 
Sheet1
Cell Formulas
RangeFormula
J2:S11J2=IF(J$1=$I2,"",SUMPRODUCT(MMULT(--($C$2:$G$10=$I2),{1;1;1;1;1})*MMULT(--($C$2:$G$10=J$1),{1;1;1;1;1})))
 
Upvote 0
You are awesome Eric.!! You have no idea how long I've been working on this. Your solution works great!! Thank you so much!!
 
Upvote 0
Glad to help! That was a fun one. Here's a slightly shorter version of it:

=IF(J$1=$I2,"",SUMPRODUCT(--(MMULT(($C$2:$G$10=$I2)+($C$2:$G$10=J$1),{1;1;1;1;1})=2)))

:cool:
 
Upvote 0
I like this version even better. I had never used, or was even aware of the MMULT function. Thanks again Eric!!
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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