简体   繁体   中英

Excel: Compare list of strings with a column of partial strings,if match then return the partial string

示例表示

I have a list of strings in Column A. I want to match the entries in column G (partial strings) with the strings in column A. If there is a match, I want to print out the partial string in Column B (output).

I have used the following formula -

=IF(SUMPRODUCT(--ISNUMBER(SEARCH(G:G,A1)))>0,"found","notfound")

to print out found or notfound string, but I am not able to print out the partial string value in column B.

Any help would be appreciated.

You can use INDEX with an AGGREGATE to return the row number:

=IFERROR(INDEX(G:G,AGGREGATE(15,6,ROW($G$2:$G$3)/(ISNUMBER(SEARCH($G$2:$G$3,A2))),1)),"")

Aggregate is an array type formula and as such the references needs to be constrained to the data set and not a full column reference.

Also the sub string must match fully in the larger string, in your example Please contact agent would not be found in Please contact the agent As the splits the string and will not match.

在此处输入图片说明


To make the formula more dynamic, so it does not need to be edited every time a sub-string is added or removed from the list and still maintain the smallest reference we can use another INDEX/MATCH to find the end of the list and set this as the end of the reference.

=IFERROR(INDEX(G:G,AGGREGATE(15,6,ROW($G$2:INDEX(G:G,MATCH("ZZZZ",G:G)))/(ISNUMBER(SEARCH($G$2:INDEX(G:G,MATCH("ZZZZ",G:G)),A2))),1)),"")

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