Fetching 2nd, 3rd, 4th (and so on) Match while Ignoring Blanks

LearnExcl

Board Regular
Joined
Mar 17, 2010
Messages
245
Office Version
  1. 2016
Platform
  1. Windows
Hi,
The below formula currently fetches the 2nd value, but it is actually the first corresponding in a cell where there is actually a value, since the first corresponding match is a blank cell. Could we revise the formula to fetch the second real value (text) ignoring all the corresponding blank cells?

Excel Formula:
=IF(SUMPRODUCT(--(INDEX($A$2:$AU$500,,MATCH("Nr",$A$1:$AU$1,0))=RIGHT(INDEX($A$1:$CU$500,ROW($A2:B2),MATCH("UMR",$A$1:$CU$1,0)),9))))>=1,IFERROR(INDEX($AM$1:$AM$500,SMALL(IF($J$1:$J$500=RIGHT(INDEX($A$1:$CU$500,ROW($A2:B2),MATCH("UMR",$A$1:$CU$1,0)),9),ROW($AM$1:$AM$500),1000000),2)),""))
 
Last edited by a moderator:
Jason, thank you so much for responding. It is actually Sheet2, Sheet3 and Sheet4 being pulled into Sheet1. I very much appreciate your support on this.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm just about to go offline for the day so this is a bit rushed. Hopefully I have it right, although I haven't had chance to test the theory.

Enter this formula into B2 and array confirm with Ctrl Shift Enter before using the fill handle to populate the rest of the table.
Excel Formula:
=IFERROR(INDEX(Sheet2!$B:$B,AGGREGATE(15,6,ROW(Sheet2!$B$1:$B$20)/(Sheet2!$A$1:$A$20=$A2)/(Sheet2!$B$1:$B$20<>""),COLUMNS($B:B))),IFERROR(INDEX(Sheet3!$B:$B,AGGREGATE(15,6,ROW(Sheet3!$B$1:$B$20)/(Sheet3!$A$1:$A$20=$A2)/(Sheet3!$B$1:$B$20<>""),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$A$1:$A$20,$A2:A2)))),IFERROR(INDEX(Sheet4!$B:$B,AGGREGATE(15,6,ROW(Sheet4!$B$1:$B$20)/((Sheet4!$A$1:$A$20=$A2)*(Sheet4!$B$1:$B$20<>"")),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$A$1:$A$20,$A2:A2),COUNTIF(Sheet3!$A$1:$A$20,$A2:A2)))),"")))
I'll check when I can to see if it worked or needs some adjustments.
 
Upvote 0
Maybe Peter will have an easier method that I'm not thinking of but given the requirements, I don't think that there will be one (except perhaps with functions that you would not have available in your version of excel).
 
Upvote 0
Hi Jason, it actually worked.
If that is so then I haven't understood the data and/or requirement.

Suppose we have these sheets
LearnExcl.xlsm
AB
1
2888
3345Gear2
4455hellen2
5345
6888Heim2
7980Rerer2
8888
9323Steph2
10345Manol2
11888Watson2
Sheet2

LearnExcl.xlsm
AB
1
2888
3345Gear3
4455hellen3
5345
6888Heim3
7980Rerer3
8888
9323Steph3
10345Manol3
11888Watson3
Sheet3

LearnExcl.xlsm
AB
1
2888
3345Gear4
4455hellen4
5345
6888Heim4
7980Rerer4
8888
9323Steph4
10345Manol4
11888Watson4
Sheet4


The the post 12 formula produces this
Cell Formulas
RangeFormula
B2:E6B2=IFERROR(INDEX(Sheet2!$B:$B,AGGREGATE(15,6,ROW(Sheet2!$B$1:$B$20)/(Sheet2!$A$1:$A$20=$A2)/(Sheet2!$B$1:$B$20<>""),COLUMNS($B:B))),IFERROR(INDEX(Sheet3!$B:$B,AGGREGATE(15,6,ROW(Sheet3!$B$1:$B$20)/(Sheet3!$A$1:$A$20=$A2)/(Sheet3!$B$1:$B$20<>""),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$A$1:$A$20,$A2:A2)))),IFERROR(INDEX(Sheet4!$B:$B,AGGREGATE(15,6,ROW(Sheet4!$B$1:$B$20)/((Sheet4!$A$1:$A$20=$A2)*(Sheet4!$B$1:$B$20<>"")),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$A$1:$A$20,$A2:A2),COUNTIF(Sheet3!$A$1:$A$20,$A2:A2)))),"")))


.. whereas my reading of the requirements would be this
Cell Formulas
RangeFormula
B2:H6B2=IFERROR(INDEX(Sheet2!$B:$B,AGGREGATE(15,6,ROW(Sheet2!$B$1:$B$20)/((Sheet2!$A$1:$A$20=$A2)*(Sheet2!$B$1:$B$20<>"")),COLUMNS($B:B))),IFERROR(INDEX(Sheet3!$B:$B,AGGREGATE(15,6,ROW(Sheet3!$B$1:$B$20)/((Sheet3!$A$1:$A$20=$A2)*(Sheet3!$B$1:$B$20<>"")),COLUMNS($B:B)-COUNTIFS(Sheet2!$A$2:$A$20,$A2,Sheet2!$B$2:$B$20,"<>"))),IFERROR(INDEX(Sheet4!$B:$B,AGGREGATE(15,6,ROW(Sheet4!$B$1:$B$20)/((Sheet4!$A$1:$A$20=$A2)*(Sheet4!$B$1:$B$20<>"")),COLUMNS($B:B)-COUNTIFS(Sheet2!$A$2:$A$20,$A2,Sheet2!$B$2:$B$20,"<>")-COUNTIFS(Sheet3!$A$2:$A$20,$A2,Sheet3!$B$2:$B$20,"<>"))),"")))
 
Upvote 0
I agree with your interpretation, Peter. My rushed formula had the wrong column references in the countif ranges.
Cell Formulas
RangeFormula
B2:H6B2=IFERROR(INDEX(Sheet2!$B:$B,AGGREGATE(15,6,ROW(Sheet2!$B$1:$B$20)/(Sheet2!$A$1:$A$20=$A2)/(Sheet2!$B$1:$B$20<>""),COLUMNS($B:B))),IFERROR(INDEX(Sheet3!$B:$B,AGGREGATE(15,6,ROW(Sheet3!$B$1:$B$20)/(Sheet3!$A$1:$A$20=$A2)/(Sheet3!$B$1:$B$20<>""),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$B$1:$B$20,$A2:A2)))),IFERROR(INDEX(Sheet4!$B:$B,AGGREGATE(15,6,ROW(Sheet4!$B$1:$B$20)/((Sheet4!$A$1:$A$20=$A2)*(Sheet4!$B$1:$B$20<>"")),COLUMNS($B:B)-SUM(COUNTIF(Sheet2!$B$1:$B$20,$A2:A2),COUNTIF(Sheet3!$B$1:$B$20,$A2:A2)))),"")))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Thank you Peter for chiming in. At fırst sight it looked like James' formula seemed to be working with the first 100 rows of data. I will check again Monday thorougly and let you both know. Appreciate the support as always.
 
Upvote 0
My rushed formula had the wrong column references in the countif ranges.
I think that your latest formula relies on specific circumstances that may or may not exist in the data sheets. I don't know what is possible with the OP's data but if you change cell B4 in Sheet2 to "Gear2" then the formula now returns incorrect results for code 345 and code 455.
 
Upvote 0
I wouldn't really call it 'latest formula', it was the same one as before but with the column references corrected.
Admittedly I hadn't allowed for the situation that you have noticed, but we could spend all day adding extra bits to formulas for specifics that might not be relevant.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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