简体   繁体   中英

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". I want to check for several terms so this should be respeatable

=IF(SEARCH("jw",E258)," jw marriott", IF(SEARCH("westin",E258)," Westin"))

etc, but it didn't work

Put your lookup and wanted outputs in a table and use XLOOKUP:

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

在此处输入图像描述


If one does not have XLOOKUP then INDEX/AGGREGATE will work:

=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.

If that is desired, change the SEARCH to include spaces:

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

Though note that if there is punctuation, that may need to dealt with also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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