Help with sum and countif

Samgraphics

Board Regular
Joined
Jan 9, 2022
Messages
52
Office Version
  1. 2011
Platform
  1. MacOS
Hi, I'm trying to create conditional formatting that will highlight the cell next to the number combination if that combination has 3 or more matching numbers and the winning number. I'm using =sum(countif()) but it's not producing the correct results. I'm not sure what is causing this. Can you please help me? Here is a snippet of the worksheet.
As you can see I tried different approaches but not getting desired results.

HIGHLIGHT THE LATEST LOTTERY MATCHES.xlsx
ABCDEFGHIJKLMNOP
1LOTTERY TICKET PURCHASE HISTORY
2
3LATEST DRAW
4NO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2
535103334710FALSE< I was testing the formula here before going to conditional formatting
6
7
8DATENO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2WINNERS
911/22/2115679910
1015789212
1119123334912
1225689911
13192630323369
14810152033712
1541115171838
16714182021611
171017212324912
181320242627312
19162327293036
20216171834410
21510212531511
LotteryTable
Cell Formulas
RangeFormula
J5J5=SUM(COUNTIF($A9:$H9,$A$5:$G$5))>=3
Named Ranges
NameRefers ToCells
number07=tbllottery[BONUS 2]J5
number08=tbllottery[BONUS 1]J5
number09=tbllottery[NO 5]J5
numberCheck=LotteryTable!$B5:INDEX(number09,COUNT(number09),1)J5
numberCheck02=LotteryTable!$G5:INDEX(number08,COUNT(number08),1)J5
numberCheck03=LotteryTable!$H5:INDEX(number07,COUNT(number07),1)J5
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I9:I88Expression=SUM(COUNTIF($A9:$H9,$A$5:$G$5))>=3textNO
A9:A88Expression=SUM(COUNTIF(B9:F9,A5:E5)+COUNTIF($G9:$H9,$F$5:$G$5))>=3textNO
H9:H88Expression=AND(COUNTIF($G$5,H9),COUNTIF(numberCheck03,H9)=1)textNO
H9:H88Expression=COUNTIF($G$5,H9)textNO
G9:G88Expression=AND(COUNTIF($F$5,G9),COUNTIF(numberCheck02,G9)=1)textNO
G9:G88Expression=COUNTIF($F$5,G9)textNO
B9:F88Expression=AND(COUNTIF($A$5:$E$5,B9),COUNTIF(numberCheck,B9)=1)textNO
B9:F88Expression=COUNTIF($A$5:$E$5,B9)textNO


Thank you in advance for your help and time.

ps I was finally able to install the xl2bb add in so if there are any problems i'm sorry.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You need to array confirm the formula for it to work. I believe that on a Mac it is done by pressing Cmd and Return / Enter together.
Note that conditional formatting formulas are entered as array by default so it will work fine there.
 
Upvote 0
I think the following will give you what you want:

Excel Formula:
=sumproduct(--($A$5:$G$5=B9:H9))>3
 
Upvote 0
we are matching it row in A5 to G5 , which is the bonus balls
against the full like
B9 to H9
??
=SUMPRODUCT(COUNTIF(B9:H9,$A$5:$G$5))>2

see K & L for the formula working -
it can then be added to a condotional formatting

Book1
ABCDEFGHIJKL
1LOTTERY TICKET PURCHASE HISTORY
2
3LATEST DRAW
4NO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2
535103334710TRUE< I was testing the formula here before going to conditional formatting
6
7
8DATENO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2WINNERS
9445221563334910TRUE2
1015789212FALSE2
1119123334912FALSE1
1225689911FALSE1
13192630323369FALSE4
14810152033712TRUE1
1541115171838FALSE1
16714182021611FALSE2
171017212324912FALSE1
181320242627312FALSE1
19162327293036FALSE3
20216171834410TRUE4
21510212531511TRUE0
Sheet2
Cell Formulas
RangeFormula
J5J5=SUM(COUNTIF($A9:$H9,$A$5:$G$5))>=3
K9:K21K9=SUMPRODUCT(COUNTIF(B9:H9,$A$5:$G$5))>2
L9:L21L9=SUMPRODUCT(COUNTIF(B10:H10,$A$5:$G$5))
 
Upvote 0
I think the following will give you what you want:

Excel Formula:
=sumproduct(--($A$5:$G$5=B9:H9))>3
Hi Jason and Rob, thank you for the quick response, much appreciated.
However, neither of these solutions are returning the correct results. I did the array but the results are not always right. There are times when there are only two matching numbers but it says true and times when there are more than 3 and it says false. I can't see what I'm missing. Did it return the correct results on your computer?
Here is a snippet.

HIGHLIGHT THE LATEST LOTTERY MATCHES.xlsx
ABCDEFGHIJKLMNOPQRST
1LOTTERY TICKET PURCHASE HISTORY
2
3LATEST DRAW
4NO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2
52493334710FALSETHIS ROW HAS MORE THAN 3 MATCHING NUMBERS IT SHOULD SAY TRUE
6FALSEthis is true but doesn't update when the numbers are added or removed
7FALSEthis should be true row 11 has 3 matching numbers
8DATENO 1NO 2NO 3NO 4NO 5BONUS 1BONUS 2WINNERSTRUEthis is correct, but if I add or remove a matching number it doesn't update and it stays true all the time
911/22/2115679910TRUEthis was also correct but I changed a number in the latest draw to 5 an it didn't update it still says true when it should be false
1015789712
1119123334912
1225689911
13192630323369
LotteryTable
Cell Formulas
RangeFormula
J5:J7J5=SUMPRODUCT(--($B$5:$H$5=$B9:$H9))>=3
J8:J9J8=SUM(COUNTIF($B11:$H11,$B$5:$H$5))>=3
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
number07=tbllottery[BONUS 2]J5
number08=tbllottery[BONUS 1]J5
number09=tbllottery[NO 5]J5
numberCheck=LotteryTable!$B5:INDEX(number09,COUNT(number09),1)J5
numberCheck02=LotteryTable!$G5:INDEX(number08,COUNT(number08),1)J5
numberCheck03=LotteryTable!$H5:INDEX(number07,COUNT(number07),1)J5
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A9:A88Expression="{=SUM(COUNTIF(B9:F9,A5:E5)+COUNTIF($G9:$H9,$F$5:$G$5))>=3}"textNO
B9:F88Expression=AND(COUNTIF($B$5:$F$5,B9),COUNTIF(numberCheck,B9)=1)textNO
B9:F88Expression=COUNTIF($B$5:$F$5,B9)textNO
G9:G88Expression=AND(COUNTIF($G$5,G9),COUNTIF(numberCheck02,G9)=1)textNO
G9:G88Expression=COUNTIF($G$5,G9)textNO
H9:H88Expression=AND(COUNTIF($H$5,H9),COUNTIF(numberCheck03,H9)=1)textNO
H9:H88Expression=COUNTIF($H$5,H9)textNO
I9:I88Expression=SUMPRODUCT(--($B$5:$H$5=B9:H9))>3textNO
 
Upvote 0
Should the bonus numbers be matched to the other numbers or be counted separately?

As suggested the array confirmation of your formula does work correctly if the bonus numbers are to be cross matched. One thing that I did not notice was that you had included the date column in the first range which will be giving you some erroneous results.

The SUMPRODUCT formula suggested by @RobVos is probably not the way to go, it will only count the numbers that are in exactly the same position. in both tables (number 3 in the first column in both tables, 5 in the second column and so on).
 
Upvote 0
I am not clear if you need all matches or unique matches.

I didn't notice you put >=, so my first formula had only > -- change the 3 to 2 and see if that is what you wanted.

Excel Formula:
=SUMPRODUCT(--($A$5:$G$5=B9:H9))>2

Else maybe:

Excel Formula:
=SUMPRODUCT(COUNTIF(B9:H9,$A$5:$G$5))>2
 
Last edited:
Upvote 0
Should the bonus numbers be matched to the other numbers or be counted separately?

As suggested the array confirmation of your formula does work correctly if the bonus numbers are to be cross matched. One thing that I did not notice was that you had included the date column in the first range which will be giving you some erroneous results.
I would like the bonus numbers to be checked against bonus numbers only and the first 5 checked against the first five in each combination. I don't want the bonus numbers to be checked against the other numbers, no.
I also noticed that I accidentally included the date column, but I corrected it and still getting the wrong results.
 
Upvote 0
I am not clear if you need all matches or unique matches.

Maybe:

Excel Formula:
=SUMPRODUCT(COUNTIF(B9:H9,$A$5:$G$5))>3
Unique matches, please. No 1, no 2, no 3, no 4, no 5 with no1, no2,no3,no4,no5 and bonus1, with bonus1 and bonus2 with bonus2. I don't know if you can understand me. sorry. I don't want the bonus numbers to be checked against the other 5 numbers.

Thank you so much. sorry if i'm not being clear enough in what I need help with.
 
Upvote 0
I would like the bonus numbers to be checked against bonus numbers only and the first 5 checked against the first five in each combination. I don't want the bonus numbers to be checked against the other numbers, no.
what does that now mean to the matching 3 ?

so you are matching

A5 to E5
agains B9 to F9
but is that for 3 mathes
and then how do the bonus balls get included ?

you can just change the range and add together

=SUMPRODUCT(COUNTIF(B9:F9,$A$5:$E$5))>2

=SUMPRODUCT(COUNTIF(B9:F9,$A$5:$E$5)) + SUMPRODUCT(COUNTIF(G9:H9,$F$5:$G$5))

or in a logic tst
 
Upvote 0
Solution

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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