使用AND或OR运算符为Excel IF ISNUMBER SEARCH查找多个文本

时间:2017-11-29 09:59:06

标签: excel

这是我的Excel数据

enter image description here

正如您在B2中所看到的,此公式仅搜索它找到的第一个文本,并忽略其余文本。

我想要完成的是,如果找到2个或更多不同的文本,例如B2,是否可以打印另一条消息......请说Apple & Banana found

enter image description here

这是我原来的excel公式供您参考:

=IF(ISNUMBER(SEARCH("apple",A2)),"Apple",
IF(ISNUMBER(SEARCH("banana",A2)),"Banana",
IF(ISNUMBER(SEARCH("cher",A2)),"Cherries",
"Other")))

3 个答案:

答案 0 :(得分:1)

查看以下公式调整是否可以帮助您:

=TRIM(CONCATENATE(IF(ISNUMBER(SEARCH("apple",A2)),"Apple "," "), IF(ISNUMBER(SEARCH("banana",A2)),"Banana "," "), IF(ISNUMBER(SEARCH("cher",A2)),"Cherries "," "), IF(SUM((ISNUMBER(SEARCH({"apple","banana","cher"},A2,1)))+0)=0,"Other "," ")))&" found"

答案 1 :(得分:1)

我已经尝试了很多,然后想到了hmmm为什么我不简单地添加一个SUBSTITUTE函数...并且有效; o)

以防万一有人在外面寻找这个东西

=SUBSTITUTE(TRIM(CONCATENATE(IF(ISNUMBER(SEARCH("apple",A2)),"Apple "," "),
IF(ISNUMBER(SEARCH("banana",A2)),"Banana "," "),
IF(ISNUMBER(SEARCH("cher",A2)),"Cherries "," "),
IF(SUM((ISNUMBER(SEARCH({"apple","banana","cher"},A2,1)))+0)=0,"Other "," "))),"Apple Banana","Both")

答案 2 :(得分:0)

这是我的建议:

使用两列的关键字和结果创建一个表 (第K列为关键字,第L列为结果)。

您可以这样更改公式

=IF(ISNUMBER(SEARCH(K2,A2)),L2, IF(ISNUMBER(SEARCH(K3,A2)),L3, IF(ISNUMBER(SEARCH(K4,A2)),L4, "Other")))

此后,如果您想比其他优先级更高的关键字,则添加新的关键字更容易,以更改顺序。

您不能使用超过63个关键字,但是您可以创建第二个公式,范围是64至126。