if the sum of 2 numbers equal to another number

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
hi!
i need to know if the sum of any 2 numbers in c2:h2 equal to some number within the same range?
for example c2+g2=h2
also, if the sum of any 2 numbers in c3:h3 equal to some number in c2:h2?
for example c3+f3=h2
don't need to know which, just if
if there's mark with 1 if not, with 0
if there's one formula that can save the helper one in i col, the better, if not, also good

Cell Formulas
RangeFormula
I2:I4I2=D2+C2&","&E2+D2&","&E2+C2&","&F2+E2&","&F2+D2&","&F2+C2&","&G2+F2&","&G2+E2&","&G2+D2&","&G2+C2&","&H2+G2&","&H2+F2&","&H2+E2&","&H2+D2&","&H2+C2
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
There's probably a better way, especially if the numbers are always ascending, but try:

Book1
CDEFGHI
2111222530311
31243032331
425121826400
Sheet2
Cell Formulas
RangeFormula
I2:I4I2=LET(r,C2:H2,s,SEQUENCE(64,,0),h,DEC2BIN(s,6),w,LEN(SUBSTITUTE(h,"0","")),t,MID(h,{1,2,3,4,5,6},1)+0,m,MMULT(t*r,{1;1;1;1;1;1})*(w=2),MAX(--ISNUMBER(MATCH(m,r,0))))
 
Upvote 0
How about:

Book1
ABCDEFGHIJ
1same groupdifferent groups
21112225303110
312430323311
4251218264001
5
Sheet2
Cell Formulas
RangeFormula
I2:I4I2=LET(r,C2:H2,s,SEQUENCE(64,,0),h,DEC2BIN(s,6),w,LEN(SUBSTITUTE(h,"0","")),t,MID(h,{1,2,3,4,5,6},1)+0,m,MMULT(t*r,{1;1;1;1;1;1})*(w=2),MAX(--ISNUMBER(MATCH(m,r,0))))
J2:J4J2=LET(ra,C2:H2,rb,C1:H1,n,2,c,COLUMNS(ra),s,SEQUENCE(2^c,,0),h,DEC2BIN(s,c),w,LEN(SUBSTITUTE(h,"0","")),t,MID(h,SEQUENCE(,c),1)+0,m,MMULT(t*ra,SEQUENCE(c,,,0))*(w=n),MAX(--ISNUMBER(MATCH(m,rb,0))))


I generalized the second formula a bit. You can define two ranges, one for the numbers to add, one for the numbers to check. You can change the number of columns just by changing the range (C2:H2 to B2:H2 for example), although you'll probably hit a limit pretty quick. You can also change the number of numbers to add from 2 to whatever you want.

Hope this helps!
 
Upvote 0
Solution
Very interesting approach, Eric. Could you have a look at the generalized formula? I believe the last function (MATCH) should be looking for "m" in "ra" rather than "rb". I'm not sure why "rb" is needed at all.
 
Upvote 0
with your permission eric, another question if you may,
is it possible to alter the formula in j2 to check the
difference in c3:h3 between any two numbers
against one in c2:h2
instead the sum ?

also, you said
I generalized the second formula a bit. You can define two ranges, one for the numbers to add, one for the numbers to check. You can change the number of columns just by changing the range (C2:H2 to B2:H2 for example), although you'll probably hit a limit pretty quick. You can also change the number of numbers to add from 2 to whatever you want.
did you meant i can check c4:h4 against c3:h3 and c2:h2 , separately, in one formula?
cause i didn't manage to do it
just replacing the range number
 
Upvote 0
Very interesting approach, Eric. Could you have a look at the generalized formula? I believe the last function (MATCH) should be looking for "m" in "ra" rather than "rb". I'm not sure why "rb" is needed at all.
Because the second part of the OP's question was:
also, if the sum of any 2 numbers in c3:h3 equal to some number in c2:h2?
where we're checking the sum of 2 numbers in one range against the numbers in another range.


is it possible to alter the formula in j2 to check the
difference in c3:h3 between any two numbers
against one in c2:h2
instead the sum ?
Hmm, much more complicated, I'll think about it.

did you meant i can check c4:h4 against c3:h3 and c2:h2 , separately, in one formula?
No, the formula only checks one row of sums with another row of numbers. If you want to compare one row against the 2 previous rows, or the 3 previous rows, or even all previous rows, I think I can do that if you want.
 
Upvote 0
Thanks for following up with an explanation to my question, Eric. I see that I misinterpreted rb. For some reason, I was assuming (incorrectly) that rb would always be a horizontal array of 0's, but that is the case only for the first row of values to be evaluated when the blank cells in row 1 are referenced. So your formula compares combinations of sums (of any 2 values on that row) to the range immediately above and "rb" will update to reference the range immediately above as the formula is pulled down the sheet.

At the risk of overcomplicating things, I suppose any contiguous range of cells that might be of interest for the final comparison could be stacked into a single vertical array and the match performed. For example, if rb were defined as:
Excel Formula:
=SORT(UNIQUE(LET(array,C2:H3,rowcount,ROWS(array),colcount,COLUMNS(array),itemcount,rowcount*colcount,MAKEARRAY(itemcount,1,LAMBDA(r,c,INDEX(array,LET(a,MOD(r,rowcount),IF(a=0,rowcount,a)),ROUNDUP(r/rowcount,0))  )))))
...we would get the range C2:H3 stacked into a single vertical array, and the final matching done by MAX(--ISNUMBER(MATCH(m,rb,0))) could answer both questions (is there a match on the current row or the row above) in one step.

If this is of interest, the single-step, multiple row match adjustment would look like this:
Excel Formula:
=LET(ra,C2:H2,rb,SORT(UNIQUE(LET(array,C2:H3,rowcount,ROWS(array),colcount,COLUMNS(array),itemcount,rowcount*colcount,MAKEARRAY(itemcount,1,LAMBDA(r,c,INDEX(array,LET(a,MOD(r,rowcount),IF(a=0,rowcount,a)),ROUNDUP(r/rowcount,0))  ))))),n,2,c,COLUMNS(ra),s,SEQUENCE(2^c,,0),h,DEC2BIN(s,c),w,LEN(SUBSTITUTE(h,"0","")),t,MID(h,SEQUENCE(,c),1)+0,m,MMULT(t*ra,SEQUENCE(c,,,0))*(w=n),MAX(--ISNUMBER(MATCH(m,rb,0))))
 
Upvote 0
At the risk of overcomplicating things, I suppose any contiguous range of cells that might be of interest for the final comparison could be stacked into a single vertical array and the match performed. For example, if rb were defined as:
Yes, I think you got the gist of it now. I don't have the MAKEARRAY function yet, so I was going to do something like this:

rb,SMALL(C2:H2,SEQUENCE(COUNT(C2:H2))),

to put the previous rows in a vertical array. That's untested, but it should work. For numeric values of course. As far as the latest request (difference instead of sum), I'm not sure I have a good solution for that. The formula is complicated enough, I think at this point it's looking like a UDF would be better. Let's see what the OP says.
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,137
Members
449,207
Latest member
VictorSiwiide

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