【问题标题】:Return which substring is in a cell from a list of substrings从子字符串列表中返回哪个子字符串在单元格中
【发布时间】:2019-02-26 16:12:46
【问题描述】:

问题

给定 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 测试,但我无法适应我的需求。非常感谢任何建议:)

【问题讨论】:

    标签: arrays excel text excel-formula substring


    【解决方案1】:

    在 B5 中:

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

    然后抄下来

    【讨论】:

    • 另外感谢您对我的问题的格式,我是新人,如果我以后再问另一个问题,我会按照您的格式应用:)
    • 感谢 Scott 的快速回复,逻辑很棒,重新评论 Scott 的回复已更新以完美解决我的第一个评论问题!
    【解决方案2】:

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

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

    因为它是一个数组公式,所以不要忘记使用 CTRLSHIFTENTER

    【讨论】:

    • 谢谢你,我目前有 2010,但将很快升级,并将测试它以学习。
    猜你喜欢
    • 2012-10-15
    • 2013-11-05
    • 1970-01-01
    • 2019-09-15
    • 2016-06-07
    • 2023-03-28
    • 2012-11-05
    • 2015-09-18
    • 1970-01-01
    相关资源
    最近更新 更多