问题
I have a list of cells with text strings (notes) and I need to check each cell if it contains a word from the search list. Each note will only contain one of the search words. If a note contain a search word, the function need to return a Level 1 text and a Level 2 text. If a note does not contain any of the search Words, the function must return "No L1" and "No L2". The note can contain the search word in any part of the textstring and it can contain both letters, numbers and basic signs such as " . - , _ "
Example:
Notes in: A2:A7
Return of Level 1 in: B2:B7
Return of Level 2 in: C2:C7
Search words in: F2:F8
Level 1 return text in: G2:G8
Level 2 return text in: H2:H8
-The search words and their return text can be in other sheet...
回答1:
In G2 Cell, you can specify the following formula
=IFERROR(INDEX(B:B,MATCH("*"&F2&"*",A:A,0)),"")
and in H2 column you can specify the following formula
=IFERROR(INDEX(C:C,MATCH("*"&F2&"*",A:A,0)),"")
After that copy these formula in below cells
If it is other way round, enter the below formula in the cell B2
=IFERROR(INDEX(G:G,SUMPRODUCT((--ISNUMBER(SEARCH(F:F,A2)))*(F:F<>""),ROW(F:F))),"")
and enter the below formula in C2
=IFERROR(INDEX(H:H,SUMPRODUCT((--ISNUMBER(SEARCH(F:F,A2)))*(F:F<>""),ROW(F:F))),"")
and now copy the formula in rest of the cells below B and C.
来源:https://stackoverflow.com/questions/39351338/if-text-string-contains-search-word-from-list-return-defined-text