从子字符串列表返回单元格中的哪个子字符串

时间:2019-02-26 16:12:46

标签: arrays excel text excel-formula substring

问题

给出Excel范围内的子字符串列表,例如:

子字符串表

[A1:A3]  
Apple  
Banana  
Carrot  

我希望返回这些子字符串中的哪个出现在包含文本的单元格中,例如:

文本单元格

[A5]  
The Apple fell from the tree  

方法/公式将返回:Apple

原因

每个月我将导入几百个包含文本并需要分类的单元格。最常见的子字符串将在顶部的子字符串范围内,即导入的文本单元格将具有一个相邻的列,该列具有一个公式,该公式可输出存在的子字符串之一,从而节省了大量的用户时间。所需的输出示例为:

所需的输出

*Table of text cells* | *Output referencing substring table* [A5:B5]  
The Apple fell from the tree | Apple  
A Carrot grows in the ground | Carrot  
There was a bag of rotten Apples | Apple  
Watch out for that Orange |  
The monkey ate the Banana | Banana  

通过修补和研究获得最接近的公式

我得到的最接近的是一个公式,如果存在子字符串(返回1或0),该公式将返回:

=SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$3,A5)))

使用此公式和上面的“所需输出”示例,我将看到:

[A5:B5]  
The Apple fell from the tree | 1  
A Carrot grows in the ground | 1  
There was a bag of rotten Apples | 1  
Watch out for that Orange | 0  
The monkey ate the Banana | 1 

在本论坛上推荐此测试为TRUE / FALSE,但我无法适应自己的需求。任何建议,不胜感激:)

2 个答案:

答案 0 :(得分:0)

在B5中:

=INDEX(A:A,AGGREGATE(15,7,ROW($A$1:$A$3)/(ISNUMBER(SEARCH($A$1:$A$3,A5))),1))

然后抄下来

答案 1 :(得分:0)

如果您有Excel 2016,则可以在数组公式中使用TEXTJOIN

{=TEXTJOIN(", ",TRUE,IF(ISNUMBER(SEARCH(A$2:A$4,A5)),A$2:A$4,""))}

因为它是一个数组公式,所以请不要忘记使用 CTRL SHIFT ENTER

enter image description here