简体   繁体   中英

Excel Index Match - Partial strings with Multiple Results

I'm trying to tweak this piece of code I found in a sample spreadsheet online but I can't quite get my head around it.

The original spreadsheet basically does an INDEX/MATCH based on a user-defined lookup and lists the matches neatly in a concatenated list. The sample spreadsheet's output looks like this:

http://i.stack.imgur.com/DyahB.png - Sample Excel Output (Note how there are no gaps between the first and second matches)

The underlying algorithm is:

=IF(ISERROR(INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2)),"",INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2))

Now, I want the lookup to instead retrieve PARTIAL matches, and in addition, generate the outputs horizontally like so:

http://i.stack.imgur.com/ShED0.png - Output is generated horizontally based on partial matches

I'm not sure how I would go about doing this. It seems like I would somehow try and change the IF condition to return true on partial matches but I can't get my head around it. Please help!

Assuming by "partial match" you mean text that starts with the value in L1 then use this formula in N1

=IFERROR(INDEX($I$2:$I$8,SMALL(IF(LEFT($H$2:$H$8,LEN($L$1))=$L$1,ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")

confirm with CTRL + SHIFT + ENTER and copy across

For a match anywhere in the text you can use this version

=IFERROR(INDEX($I$2:$I$8,SMALL(IF(ISNUMBER(SEARCH($L$1,$H$2:$H$8)),ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")

Neither formula is case-sensitive, although you can easily make the latter so by changing SEARCH to FIND

Use of IFERROR function means you don't need repetition for error handling - needs Excel 2007 or later version

Building on Barry's code a little, I needed to make a few tweaks for my own use (current project I have at work).

Tweaks I made:

  1. Returning the cell that matches my search criteria in my index
  2. Making the cell draggable in two dimensions so I could index multiple columns for specific information
  3. Making the "nth" counter vertical instead of horizontal (as my application is a database of sorts, and each column is a separate entry. At the top of each column is 5 rows populated based on the search term [in my case, the store number])

The final result is:

=IFERROR(INDEX(A$8:A$295,SMALL(IF(ISNUMBER(SEARCH('Store History'!$F$2,A$8:A$295)),ROW(A$8:A$295)-ROW(A$8)+1),ROWS(A$2:A2))),"")

It is worth repeating that this is an array formula and needs to be entered using CTRL + SHIFT + ENTER

This is placed in cell A2 and is dragged both vertically and horizontally (horizontally in my case is ever expanding as I add more entries into my database).

My purpose for adding this comment (even though it is a long inactive thread) is to try and make this a more relevant search result on Google for "excel index match partial strings with multiple results" or variations of that. It took me hours of searching to find this solution, and it is extremely functional and elegant. My thanks to the OP and especially to Barry for his code!!

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