How to find if substring exists in a list of strings (and return full value in list if so)

心已入冬 提交于 2019-12-18 09:40:58

问题


I have a list of brand names in A5:A7655 I have a list of potential substrings in D5:D1400

I need to find a corresponding brand name for each substring where possible. Most of these substrings are contained in one of the cells in the brand name list. Returning the first brand name on the list that constains the substring is fine.

For example: My substring in D5 is "ABC Studios" - if i search my whole list I see that there is a brand name "ABC Studios, LLC". In E5 I want to return ABC Studios, LLC. If there is no match in the list returning 0 or something is fine.

I played around with =ISNUMBER(SEARCH(A5,$D$5:$D$1400)) with no success. Thanks!


回答1:


Finding the last matching string is actually slightly more straightforward in terms of the formula:

=IFERROR(LOOKUP(2^15,SEARCH(D5,$A$5:$A$7655),$A$5:$A$7655),"No Match Found")

For finding the first matching string:

=IFERROR(INDEX($A$5:$A$7655,MATCH(TRUE,INDEX(ISNUMBER(SEARCH(D5,$A$5:$A$7655)),,),0)),"No Match Found")

Regards




回答2:


In E5 enter:

=IFERROR(OFFSET(A5,MATCH("*" & D5 & "*",A5:A7655,0)-1,0),"")

and copy down.




回答3:


I would suggest doing this with a two-dimensional grid. Use the brand names as the left column (the row labels), and the substrings as the top row (the column headers). Then the formula in B2 would be:

=IF(ISERROR(FIND(B$1,$A2)),B$1,$A2)

Fill that formula across and down, and the row at the bottom will be filled with the last brand name found for each substring. If no brand name is found, it will simply return the substring. (You could make it return empty instead by changing the formula in the first row after the fill down is complete - replace B$1 with "".)



来源:https://stackoverflow.com/questions/24043065/how-to-find-if-substring-exists-in-a-list-of-strings-and-return-full-value-in-l

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