简体   繁体   中英

excel find the second match to an index match formula

I have the following formula:

=INDEX(A:A;MATCH(1;(B:B=H1)*(C:C=I1)*(NOT(ISBLANK(D:D))))*((ISBLANK(E:E))));0))

now i want to pull the second result from the A:A column that matches this formula and the conditions in the match function. With this function, I only get the ABCDE which is the first match(result), but there is another FGHI that also matches this formula. But it comes several cells below the first one. My first match is ABCDE, and my second match is FGHI. I want to fetch the latter. I have tried different ways, but I can't get around this one. Please help me in this regard. thank you.

You are going to want to cut down the full column references to something that more closely approximates the actual extents of your data. My preferred method is to incorporate SMALL against an INDEX array of row numbers that will replace the MATCH in your original formula.

=INDEX(A$2:A$9999; SMALL(INDEX(ROW($1:$9998)+((B$2:B$9999<>H1)+(C$2:C$9999<>I1)+NOT(LEN(D$2:D$9999))+NOT(LEN(E$2:E$9999)))*1E+99;;); ROW(1:1)))

I used a simple Find & Replace to change my comma list separators to semi-colons so I apologize if that needs minor editing to work on your system,

When transcribing for your own purposes, remember that ROW($1:$9998) is the position within A$2:A$9999 and not the actual row on the worksheet. ROW(1:1) is simply an incremental counter for SMALL that will provide 1, 2, 3, etc as you fill down.

WOW! Thanks. Here is the ultimate working version. I had minor errors in my adaptation:

=INDEX(INDIRECT("'"&file_list!$C$3&"'!$F$2:$F$999"); SMALL(INDEX(ROW(INDIRECT("'"&file_list!$C$3&"'!$1:$998"))+((INDIRECT("'"&file_list!$C$3&"'!$B$2:$B$999")<>parameters!$C$3)+(INDIRECT("'"&file_list!$C$3&"'!$i$2:$i$999")<>parameters!$A$2)+NOT(LEN(INDIRECT("'"&file_list!$C$3&"'!$d$2:$d$999")))+(LEN(INDIRECT("'"&file_list!$C$3&"'!$H$2:$H$999"))))*1E+99;;); ROW(INDIRECT("'"&file_list!$C$3&"'!$2:$2"))))

You are a hero.

Addendum by Jeeped:

I'm nowhere near a hero until you understand how that actually works. I tried to put this in a comment but I was too long by half so I am using my editing privileges in the hope of clarification.

It's very important to understand how that combination of Excel native functions works if you hope to use the principals in the future. The first ROW(INDIRECT("'"&file_list!$C$3&"'!$1:$998") will work as written but would be better as ROW($1:$998") . This is just returning a number (ie matching row within "'"&file_list!$C$3&"'!$F$2:$F$999" . It does not matter where the number comes from. The conditions further into the formula determine whether it is a valid row number or not and those DO require the worksheet name from file_list!$C$3 because their cell value is being examined.

In a similar manner ROW(INDIRECT("'"&file_list!$C$3&"'!$2:$2")) should be ROW(2:2) if you want the second matching row within '"&file_list!$C$3&"'!$F$2:$F$999" . This portion of the formula is just an increment for SMALL . If you put row(1:1) in a cell and fill down you will get 1, 2, 3, etc . This transfers into the SMALL function as SMALL(<a bunch of matching row numbers>, first) then SMALL(<a bunch of matching row numbers>, second) then SMALL(<a bunch of matching row numbers>, third) etc. You are not trying to return Sheet1!A1,Sheet1!A2,Sheet1!A3,etc . Allk you want is 1, 2, 3, etc to stuff into SMALL as the k parameter.

The Office.Microsoft.com Excel function reference are not always the most helpful place to go but here they are anyways.

ROW function

SMALL function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM