简体   繁体   中英

Excel check if cell contains text from list and return value from list

I've seen many posts about the subject, but in general the question has been to return the value of a cell if the cell contains text from a list. I have used the following formula for that:

=IF(OR(INDEX(COUNTIF(Cell;"*"&Array&"*");));1;0)

However, what I want is to check if a cell contains text from a list, and if this is TRUE then show the text from the list, not the cell. A small example below.

In column AI have the following values

abc123
def123
ghi123
jkl123

In column B (the list)

abc
def
jkl

Now the first cell (abc123) is in the list, i want to show the text from the list (abc) in the formula cell.

I hope this is clear.

You can use following array formulas:

  • If the text you are searching is always placed at the beginning of the string

    {=INDEX($B$1:$B$3;MATCH(1;SEARCH(TRANSPOSE($B$1:$B$3);A1);0);0)}

  • or if the text you are searching is placed anywhere

    {=INDEX($B$1:$B$3;MATCH(1;--(SEARCH(TRANSPOSE($B$1:$B$3);A1)>0);0);0)}

Array formula after editing is confirmed by pressing ctrl + shift + enter

在此处输入图片说明

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