checking for combinations in multiple rows

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
hi!
have a list of numbers either separate or joined (whatever is more comfortable)
1 2 3 4
1234
1235
1236
1237
1237
1345
1346
1347
for thousands of rows
i want to check IF there's 3 out of the 4, in any order, for each line, in the next (upwards) 10 rows
and also 4 out of 4 in any order and etc....



20.xlsm
CDEFG
421855812
574133147
674211247
731177113
813144131
946433464
1088544588
1121733712
1288722788
1322811822
1483744738
1544222244
1673177137
1771311317
20
Cell Formulas
RangeFormula
G4:G17G4=F4&E4&D4&C4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G:GCell Value=1textNO
G:GCell Value=1textNO






edit: for the one below
got it with multiple =AND(COUNTIFS(


and if it's allowed another small question:
for testing and calc the data for the above question,
it seems i can't use IF and AND with numbers?
trying to to check if and combination of 3's from 1234 are repeating
1,2,3 or 1,2,4 or 1,3,4 or 2,3,4
and like you see it retures true=1 when it shouldn't


00.xlsx
ABCDEFGH
111111111
213121111
314131111
411141111
00
Cell Formulas
RangeFormula
E1:E4E1=IF(AND(A1:D1,"1", A1:D1,"2", A1:D1,"3"),1,0)
F1:F4F1=IF(AND(A1:D1,"1", A1:D1,"2", A1:D1,"4"),1,0)
G1:G4G1=IF(AND(A1:D1,"1", A1:D1,"3", A1:D1,"4"),1,0)
H1:H4H1=IF(AND(A1:D1,"2", A1:D1,"3", A1:D1,"4"),1,0)
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You can try something like this:

Book1
ABCDEFGHIJK
1
2
3
421855812321853
574133147374133
674211247374213
731177113431174
813144131313143
946433464346433
1088544588388543
1121733712321733
1288722788388723
1322811822222812
1483744738283742
1544222244044220
1673177137473174
1771311317071310
18
Sheet10
Cell Formulas
RangeFormula
G4:G17G4=F4&E4&D4&C4
H4:H17H4=MAX(MMULT(--ISNUMBER(FIND(C4:F4,J5:J14)),{1;1;1;1}))
K4:K17K4=MAX(MMULT(--ISNUMBER(FIND(MID(J4,{1,2,3,4},1),J5:J14)),{1;1;1;1}))


The H4 formula works if you have the digits separated, the K4 formula works if the digits are joined (it looks at column J). The result is the maximum number of digits that match when comparing the current row with the next 10 rows. So by your example, the rows with 4 should be highlighted in red, the ones with 3 should be highlighted in blue. You can do the Conditional Formatting off of the helper column, or you can embed the formula into Conditional Formatting itself without a helper column.

A few thoughts about your example. You did not highlight row 4, but there are 3 matches in row 13. Oversight? Also note row 8 (1314). It says there are 3 matches with row 11 (2173). The 3 matches are the 3, and the 2 "1"s both match the single 1 in 2173, so it adds up to 3. How do you want to calculate duplicated characters? Only count them if there's a unique 1 for every unique 1 in the source number? That's a tougher formula I'll have to think about.

And do you still want the second question answered? I wasn't sure with the strikethrough, but I can see that the AND wasn't formatted in any very useful way.
 
Upvote 0
row 4 = oversight, yes...
as for rows 8 and 13, yes, i would please like to count them as uniques, if the source have one "1" then the counting will count only once, and if the source have two 1's then the counting will count only twice (if there's twice...)
maybe the unique function can help?

didn't understand what "the AND wasn't formatted" but if it's 'easy peasy' and no trouble for you, i'll glad to a better solution although for the time being i managed

last note, if you please... i wanted it backworks, for example:
in row 16
=MAX(MMULT(--ISNUMBER(FIND(C16:F16,J6:J15)),{1;1;1;1}))
no biggie, can always changed it

thank you so much for all the effort!
 
Upvote 0
The formula doesn't care if the numbers are forwards or backwards. To get the "multiple instances" problem solved, I had to come up with a completely different approach:

Book1
ABCDEFGH
1
2
3
4218558123
5741331473
6742112473
7311771134
8131441313
9464334642
10885445882
11217337123
12887227882
13228118222
14837447382
15442222440
16731771373
17713113170
18
Sheet10
Cell Formulas
RangeFormula
G4:G17G4=F4&E4&D4&C4
H4:H17H4=MAX(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1)))


Note that this formula requires both the single digit columns and the concatenated column, but that can be changed.

As far as your second request, I don't understand what you want, your description doesn't seem to match the example. But I can see that the AND statement is not formatted in a useful way. It is accepted but doesn't really do anything useful. If you have something you're happy with, that's fine. If not, then please provide an example of what you want and I'll look at it.
 
Upvote 0
Solution
"The formula doesn't care if the numbers are forwards or backwards."
didn't meant to the numbers 1234 or 4321 but to the range, instead of checking, say, row c14:f14 against g15:g24 meant to check it against g13:g4

for the other question, no need, thank you

P_E_R_F_E_C_T !
🙏
THANK YOU!

2 more little (hoping) things:
any way to add an option to somehow wrote how many times 3 or 4 returns for each number in the next column (i) to the array in question? like g17 return in g16+g11

and also maybe copying to next column (j) the ones repeated of 3 or 4?

20.xlsm
CDEFGHIJKL
946433464
1088544588count repeated 3's?which 3's repeated?count repeated 4's?which 4's repeated?
11217337123
12887227882
13228118223
14837447383
15442222443
16731771373
17713113173
18741881473
19244664423
20462552643
21647117463
2271488417426471-837417418
23642662463
20
Cell Formulas
RangeFormula
G9:G23G9=F9&E9&D9&C9
H11:H23H11=MAX(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G1:G10="","aaaa",G1:G10),C11,"",1),D11,"",1),E11,"",1),F11,"",1)))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G:GCell Value=1textNO
G:GCell Value=1textNO
 
Upvote 0
Try:

Book1
ABCDEFGHIJKL
1
2
3Max match in next 10 rows# of 3 matches3 matches# of 4 matches4 matches
4218558123118220 
574133147351247, 7113, 4131, 3712, 47380 
6742112473137120 
731177113434131, 3712, 713711317
8131441313113170 
94643346420 0 
108854458820 0 
1121733712327137, 13170 
128872278820 0 
132281182220 0 
148374473820 0 
154422224400 0 
16731771373113170 
177131131700 0 
18
Sheet10
Cell Formulas
RangeFormula
G4:G17G4=F4&E4&D4&C4
H4:H17H4=MAX(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1)))
I4:I17I4=SUM(--(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1))=3))
J4:J17J4=IFERROR(TEXTJOIN(", ",1,FILTER(G5:G14,(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1))=3))),"")
K4:K17K4=SUM(--(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1))=4))
L4:L17L4=IFERROR(TEXTJOIN(", ",1,FILTER(G5:G14,(4-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(G5:G14="","aaaa",G5:G14),C4,"",1),D4,"",1),E4,"",1),F4,"",1))=4))),"")


As far as searching backwards (toward the top of the sheet), that's no problem. Just change the G16:G25 range to G5:G14 in all the formulas. Of course if your first row is 4, you can't just subtract 11 from each row, since you'd end up with a negative row. I'd suggest starting your data on row 11, much easier than making a complicated formula even more complicated.
 
Upvote 0
blob-discors.gif
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,851
Members
449,051
Latest member
excelquestion515

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