我需要进行查找并根据文本是否包含它来返回值。
请参阅下面的Excel工作表,我需要的是一个公式,这将有助于我的“类别”列填写查找表的“类别”列。
注意:请在下面的链接中查看我的Excel表格。
我尝试了公式“=VLOOKUP(B2,A13:B16,2,TRUE)
”,但没有给出预期的结果。
答案 0 :(得分:1)
This is a slight twist on the normal "find this string inside a list of others". It requires an array formula that searches for matches using FIND
.
Picture of ranges
Formula in cell A2
is an array formula (entered with CTRL + SHIFT + ENTER) and is copied down for each item. It searches in the list of lookup
for an item that is included in item
and returns the result from category
associated with lookup
.
=INDEX($E$2:$E$4,MIN(IF(IFERROR(FIND($D$2:$D$4,B2)>0,FALSE),ROW($D$2:$D$4)))-ROW($E$1))
How it works
INDEX
is returning from category
and needs a row number to returnFIND
which will check if a string is included in part of another string. In this case, the string to search for is the lookup
table and we are matching within the item
.FIND
will return #VALUE!
if no match is found, this is converted to FALSE
with IFERROR
because #VALUE!
will no work with MIN
later.IF
will then return the ROW
number or FALSE
for the match that was found.MIN
is used to convert the list of ROW
numbers to the smallest number. This means that multiple matches are not handled.ROW
number is then used as the return for the INDEX
. There is an offset applied here -ROW(E1)
which allows for the data tables to start in a row other 1:1
.