Excel:查找包含的文本

时间:2015-06-12 08:15:50

标签: excel text excel-formula contains lookup

我需要进行查找并根据文本是否包含它来返回值。

请参阅下面的Excel工作表,我需要的是一个公式,这将有助于我的“类别”列填写查找表的“类别”列。

注意:请在下面的链接中查看我的Excel表格。

data provided by user

我尝试了公式“=VLOOKUP(B2,A13:B16,2,TRUE)”,但没有给出预期的结果。

1 个答案:

答案 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

ranges and results

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 return
  • The row number is determined by using FIND 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.
  • The 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.
  • This 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.