Using sumproduct with left and right

LuGyver

Board Regular
Joined
Mar 13, 2014
Messages
88
Office Version
  1. 2007
Platform
  1. Windows
The following task seems simple... I just hope it is possible
I will break this down into pieces to see each step because it boggles my head when I try to build a formula all the steps at once.
NOTE: it is okay if the steps have to be done in separate ranges. However I want to keep them in rows and not columns.

First data is in over one thousand rows, but to keep it simple, I say data is in A1:Y1 range.
Second, the set of single Digits in A2:E2 are changed manually.
Lastly, I would like the sumproduct formula done all in one row (ie A3:Y3) if it can be. However, I am splitting the steps to include A4:Y4 and A5:Y5 for simplicity in seeing what I am after....

1. In the range A1:Y1 I have pairs such as 12 23 13 34 72 43 95 63 48 17 etc.

2. in a second range, say A2:E2, I have single digit(s), which I enter as needed, such as 1 5 7 3 6

I would like to have sumproduct() look at the right of all the pairs in A1:Y1 and return all that match any of the digits in Range A2:E2.

In this case sumproduct in range A3:Y3 returns 23 13 43 63 95 17.

3. in range A4:Y4 I need sumproduct to look at the resulting pairs left digits, and return all the pairs the have their left digit = to the left digit(s) of the pairs results in A3:Y3..

In the case above, we would see the left digit of our original return from A3:Y3 which is = 23 13 43 63 95 17:
so those left digits are 23 = 2, 13 = 1, 43 = 4, 63 = 6, 95 = 9, 17 = 1 ------ (2, 1, 4, 6, 9, 1)

so we are now looking for any pairs in A1:Y1
that have left digits = 2, 1, 4, 6, 9, 1

4. The results in A4:Y4 would be 23 13 43 63 95 17 minus(-) the first results (from A3:Y3) = 48 (and any other pairs which arise). These results stay and will remain for the remained of the calculation AND include the following.

5. In A5:Y5, sumproduct needs to look at the results in A4:Y4 and bring any pairs from A1:Y1 that have the left and/or right digits from A4:Y4. in this case = 48 = digits 4, 8
so sumproduct will be looking for left or right digits from A1:Y1 which are = 4, 8 and then return 43, 34 and include 48

The final results are 43, 34, 48

This seems easy but I don't understand sumproduct enough yet. I have been using if() with countif(s) which is not efficient and gets real confusingly cumbersome.

Hope this is said well enough
Thank you for your time and help
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
4. The results in A4:Y4 would be 23 13 43 63 95 17 minus(-) the first results (from A3:Y3) = 48 (and any other pairs which arise). These results stay and will remain for the remained of the calculation AND include the following.

You lost me here - where does 48 come from?

Also shouldn't A4:Y4 include 12 as that also has left digit 1?
 
Upvote 0
You lost me here - where does 48 come from?

in step 3, the resulting left digits of the pairs A1:Y1 are 2, 1, 4, 6, 9, 1 and we want sumproduct to now bring out any pairs from A1:Y1 whose left digit are the same.
The results should be pairs 23 13 43 63 95 17 and 48. AND sumproduct should now minus all that are the same as the results from step 2 of which = 23 13 43 63 95 17, leaving 48.


Also shouldn't A4:Y4 include 12 as that also has left digit 1?

Yes my bad. so all A3:Y3 returns should have resulted in 12 23 13 43 63 95 17

Thanks for keeping me straight
 
Upvote 0
Interesting problem.

Excel 2012
ABCDEFGHIJKL

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]72[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]17[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A3[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A4[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$3:$Y$3,1)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A5[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF((MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$4:$Y$4,1)),1,0))+MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(RIGHT($A$4:$Y$4,1)),1,0)))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Put the formulas in A3:A5, confirming each with Control+Shift+Enter. Then copy A3:A5 and drag to the right as far as needed.

If you want/don't mind if the numbers are shown in sorted order, we can actually shorten the formulas a bit:

Excel 2012
ABCDEFGHIJKL

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]72[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]95[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A3[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A4[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$3:$Y$3,1)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A5[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF((MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$4:$Y$4,1)),1,0))+MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(RIGHT($A$4:$Y$4,1)),1,0)))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Let us know how this works for you.
 
Upvote 0
Eric This works wonderfully. We are perfect in A3:Y3. However, A4:Y4 and A5:Y5, albeit absolutely perfect results, end up putting every pair in A1:Y1 back into the mix. So I'm pretty sure I may have explained something in the wrong manner.

Please allow me some time to look at this a little longer and I will get back with you for a possible tweak.

On the bright side we are leaps ahead than when we started and that is huge to me.

Thank you so much!
 
Upvote 0
Interesting problem.

Excel 2012
ABCDEFGHIJKL

<tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]72[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]17[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]A3[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
[TR]
[TH]A4[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$3:$Y$3,1)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
[TR]
[TH]A5[/TH]
[TD="align: left"]{=IFERROR(INDEX($A$1:$Y$1,SMALL(IF((MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$4:$Y$4,1)),1,0))+MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(RIGHT($A$4:$Y$4,1)),1,0)))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Put the formulas in A3:A5, confirming each with Control+Shift+Enter. Then copy A3:A5 and drag to the right as far as needed.

If you want/don't mind if the numbers are shown in sorted order, we can actually shorten the formulas a bit:

Excel 2012
ABCDEFGHIJKL

<tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]72[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]95[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]63[/TD]
[TD="align: right"]95[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]48[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]A3[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
[TR]
[TH]A4[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$3:$Y$3,1)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
[TR]
[TH]A5[/TH]
[TD="align: left"]{=IFERROR(SMALL(IF((MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(LEFT($A$4:$Y$4,1)),1,0))+MMULT(COLUMN($A$1:$Y$1)^0,IF(LEFT($A$1:$Y$1,1)=TRANSPOSE(RIGHT($A$4:$Y$4,1)),1,0)))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



Let us know how this works for you.

Hi Eric W!
Two things. I should have told you I use Excel 2007 so not sure if formula is affected by 2012.
Also, can you break down the formula(s) and explain the sections of each of the three.
I really like the way they work and think I can manipulate once I have a clear picture of how they work.
Thank you
 
Upvote 0
end up putting every pair in A1:Y1 back into the mix.

I kind of thought that might happen. If I understand your process correctly, if you get a large enough, randomized sample size, it will have the effect of grabbing everything. As far as explaining the formulas, welllll . . . how much algebra do you remember? Specifically, raising numbers to the 0th power, Boolean arithmetic, and matrix multiplication? Those formulas use all of those, and explaining how they work might take more background explanation than we have space in this thread. Not to mention Excel specific quirks on how to apply those, like why do I need to use TRANSPOSE?

Here's a real brief synopsis of the first formula:

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

The part in red compares the right digit of each number in A1:Y1 against the digits in A2:J2. Since RIGHT returns a string, I added the &"" to make the numbers in A2:J2 to strings. If they match, the IF returns a 1, otherwise a 0. I use the TRANSPOSE to convert the horizontal array A2:J2 into a vertical array, so the result of the IF is a 2-dimensional array. Each row represents a number in the A1:Y1 range, and each column in the row is a 0 or a 1 if the right digit matches A2:J2.

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

The COLUMN returns the column number of A2:J2, or 1:10, and raising it to 0 (^0) changes them all to 1, giving an array of {1;1;1;1;1;1;1;1;1;1}.

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

When you do a matrix multiplication of a unit vector {1;1;1;1;1;1;1;1;1;1} times a 2-D array, this has the effect of adding up the elements of each row, returning a 1-D array. So each element in the 1-D array now represents how many matches each number in A1:Y1 has to the number in A2:J2. If all the numbers in A2:J2 are distinct, the numbers in the 1-D array should all be 0 (the number matches nothing) or 1 (the number matches something - we don't know which, and we don't care).

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

This part just checks to see if A1:Y1 is empty or not, so we don't match on a blank cell. The * is the multiplication sign, but in this kind of array processing, it also means AND.

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

So if we match on some number (the previous step) AND it's not an empty cell, we want to keep it. If both those things are true, then we add the numbers from A1:Y1 to an internal array. If at least one of those things is NOT true, then the result of the IF is the default FALSE value.

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

COLUMNS returns the number of columns in the range. As you drag the formula to the right, it becomes $A$1:B1, $A$1:C1, etc., and COLUMNS makes it 1,2,3, etc. making this a counter.

=IFERROR(SMALL(IF(MMULT(COLUMN($A$2:$J$2)^0,IF(RIGHT($A$1:$Y$1,1)=TRANSPOSE($A$2:$J$2&""),1,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")

Finally, the SMALL takes the nth smallest number from the array, ignoring non-numeric values such as FALSE, using the counter from the last step. If the counter exceeds the number of numeric elements in the array, it generates an error, which IFERROR handles.


The first set of formulas save the column number instead of the actual value, and give it to INDEX to get it. The second formula uses ISERROR(MATCH to decide if the number exists in A3:Y3. And a + is the equivalent of OR in the third formula.

That's the gist of it. I don't believe there's anything in those formulas that 2007 can't handle. Good luck!
 
Upvote 0
Ohhhhh Molly that's incredible you took that much time for this... hey I believe I found the error I made. gotta run for the moment but will get back with you and I think it is a simple change.
Thank you
 
Upvote 0
That break-down you gave is incredible.
Here's where I believe I made my error -

correction in bold:

3.
in range A4:Y4 I need sumproduct to look at the resulting pairs left digits, and return all the pairs the have their left digit = to the Right digit(s) of the pairs results in A3:Y3..

In the case above, we would see the left digit of our original return from A3:Y3 which is = 12 23 13 43 63 95 17:
so those left digits are 12 = 1, 23 = 2, 13 = 1, 43 = 4, 63 = 6, 95 = 9, 17 = 1 ------ (1, 2, 1, 4, 6, 9, 1)

so we are now looking for any pairs in A3:Y3
that have right digits = 2, 1, 4, 6, 9, 1

Thank you
 
Upvote 0
Easy enough. The A4 formula changes to:

=IFERROR(INDEX($A$1:$Y$1,SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1)=TRANSPOSE(RIGHT($A$3:$Y$3)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),COLUMN($A$1:$Y$1)),COLUMNS($A$1:A1))),"")

or

=IFERROR(SMALL(IF(MMULT(COLUMN($A$3:$Y$3)^0,IF(LEFT($A$1:$Y$1)=TRANSPOSE(RIGHT($A$3:$Y$3)),1,0))*ISERROR(MATCH($A$1:$Y$1,$A$3:$Y$3,0))*($A$1:$Y$1<>""),$A$1:$Y$1),COLUMNS($A$1:A1)),"")
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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