excel search for multiple items

自作多情 提交于 2019-12-02 17:54:09

问题


I am trying to search for multiple items in a cell. If any of the terms I am looking for is present, I want cell D to display "Laptop", otherwise, display "Desktop". I can get the following to work, with just one term to search for:

=IFERROR(IF(SEARCH("blah",A2),"Laptop",""),"Desktop")

But I want to search for the presence of blah, blah2, and blah3. I don't know how to get Excel to search for any of the following terms. (Not all of them mind you, just any of the following.

I did see that there is an or option for the logic.

=OR(first condition, second condition, …, etc.)

I am not sure how to get these two to work together. Any thoughts on how to get them to display "Laptop" if any of the words are present?


回答1:


This should work:

=IF(SUM(COUNTIF(A2,"*" &{"blah1";"blah2";"blah3"}& "*"))>0,"laptop","desktop")



回答2:


You could use the combination of OR, IFERROR and SEARCH as you suggest, but I think the simpler construct would be ...

=IF(AND(ISERROR(SEARCH("value1",A2)),ISERROR(SEARCH("value2",A2))),"Desktop","Laptop")



来源:https://stackoverflow.com/questions/22753176/excel-search-for-multiple-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!