简体   繁体   English

如何在 Excel 中搜索多个词并返回一个短语?

[英]How to Search for Multiple Terms in Excel and Return a Phrase?

I'm trying to check if a term is present in one cell, and then return a value if that term is present.我正在尝试检查一个单元格中是否存在一个术语,如果该术语存在则返回一个值。
For example, in the cell A1, the phrase "marriott marquis houston" is present, I want, if the word "marquis" is present, for there to be an output in cell B1 saying "marquis".例如,在单元格 A1 中,存在短语“marriott marquis houston”,如果存在单词“marquis”,我希望在单元格 B1 中有一个 output 说“侯爵”。 I want to check for several terms so this should be respeatable我想检查几个术语,所以这应该是可重复的

=IF(SEARCH("jw",E258)," jw marriott", IF(SEARCH("westin",E258)," Westin")) =IF(搜索(“jw”,E258),“jw万豪”,IF(搜索(“威斯汀”,E258),“威斯汀”))

etc, but it didn't work等,但它没有工作

Put your lookup and wanted outputs in a table and use XLOOKUP:将您的查找和想要的输出放在一个表中并使用 XLOOKUP:

=XLOOKUP(TRUE,ISNUMBER(SEARCH(G1:G2,A1)),H1:H2,"")

在此处输入图像描述


If one does not have XLOOKUP then INDEX/AGGREGATE will work:如果没有 XLOOKUP 则 INDEX/AGGREGATE 将起作用:

=INDEX(H:H,AGGREGATE(15,7,ROW(G1:G2)/(ISNUMBER(SEARCH(G1:G2,A1))),1))

在此处输入图像描述


One note on these.关于这些的一个注释。 this will return Westin if Westing is found in the text string, it does not look at whole words.如果在文本字符串中找到Westing ,这将返回Westin ,它不会查看整个单词。

If that is desired, change the SEARCH to include spaces:如果需要,请将 SEARCH 更改为包含空格:

SEARCH(" "&G1:G2&" "," "&A1&" ")

Though note that if there is punctuation, that may need to dealt with also.尽管请注意,如果有标点符号,则可能也需要处理。

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

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