简体   繁体   English

Excel索引匹配-具有多个结果的部分字符串

[英]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. 原始电子表格基本上是根据用户定义的查找执行INDEX / MATCH的,并将匹配的内容整齐地列出在串联列表中。 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) http://i.stack.imgur.com/DyahB.png-Excel输出示例(请注意,第一场和第二场比赛之间没有间隙)

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: 现在,我希望查找取而代之的是检索PARTIAL匹配项,此外,像这样水平生成输出:

http://i.stack.imgur.com/ShED0.png - Output is generated horizontally based on partial matches http://i.stack.imgur.com/ShED0.png-根据部分匹配水平生成输出

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. 似乎我会尝试以某种方式尝试更改IF条件,以在部分比赛中返回true,但我无法解决。 Please help! 请帮忙!

Assuming by "partial match" you mean text that starts with the value in L1 then use this formula in N1 假设“部分匹配”是指以L1的值开头 ,然后在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 使用CTRL + SHIFT + ENTER确认并复制

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 这两个公式都不区分大小写,尽管您可以通过将SEARCH更改为FIND轻松实现后者

Use of IFERROR function means you don't need repetition for error handling - needs Excel 2007 or later version 使用IFERROR函数意味着您不需要重复进行错误处理-需要Excel 2007或更高版本

Building on Barry's code a little, I needed to make a few tweaks for my own use (current project I have at work). 在Barry的代码上稍加构建,我需要做一些调整以供自己使用(当前正在进行的项目)。

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]) 使“第n个”计数器为垂直而不是水平(因为我的应用程序是各种各样的数据库,并且每一列都是一个单独的条目。每列的顶部是基于搜索词填充的5行[在我的情况下是商店数])

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 值得重复的是,这是一个数组公式,需要使用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). 它放置在单元格A2中,并且在水平和垂直方向上都进行了拖动(在我的情况下,水平扩展是在向数据库中添加更多条目时进行的)。

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. 我添加此评论(即使它是一个很长的不活动线程)的目的是,尝试使它成为Google上更相关的搜索结果,以“ excel索引匹配具有多个结果的部分字符串”或其他形式。 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!! 感谢OP,尤其是Barry的代码!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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