简体   繁体   English

Excel-在单元格中查找部分匹配项,然后从另一个表返回匹配的类别

[英]Excel - Look for partial matches in a cell and return the matched category from another table

I have a table (Table1) with "Keywords" down one column, and their corresponding "Category" in the next column, for example: 我有一个表格(Table1),其中一栏的下方是“关键字”,而下一栏则是其对应的“类别”,例如:

Keyword Category
 EE     Telecommunications
 Water  Utilities
Amazon  Internet Transaction

On a separate worksheet, I have another table (Table2) of transactions. 在单独的工作表上,我有另一个事务表(表2)。 I want to check if any of the Keywords from Table1 are in the description of each transaction in Table2, and if so, return the corresponding Category (from Table1). 我想检查Table2中每个事务的描述中是否有Table1中的任何关键字,如果是,则返回相应的Category(来自Table1)。 If multiple matches are found, I just need a value returned to indicate so (so either the name of the only category matched, blank for no matches found, or another value (eg 'Multiple') if more than one matches were found). 如果找到了多个匹配项,我只需要返回一个值即可表明这一点(因此,可以找到唯一匹配的类别的名称,如果没有找到匹配项,则为空白;如果找到多个匹配项,则为另一个值(例如“ Multiple”))。

I have tried INDEX/MATCH and SEARCH combinations, and I've been researching for hours. 我尝试了INDEX/MATCHSEARCH组合,并且已经研究了数小时。 I'm pretty sure I need to use an {array} formula, but I just cannot get it right. 我很确定我需要使用{array}公式,但是我无法正确使用它。

I've also tried VBA to run through each row in Table2 to check against each row in Table1 which does work, but takes a very, very long time with lots of transactions. 我还尝试了VBA遍历Table2中的每一行,以检查Table1中的每一行是否正常工作,但是要花很多时间来处理大量事务。

Table2 needs to look something like this: Table2需要看起来像这样:

Description    Category
PAYPAL PAYMENT Internet Transaction
AVIVA          Insurance
BD270 MKN      
Anglian Water  Utilties
ATM 32334      <multiple matches>

This will do what you want, though I don't promise it will be very efficient with several records. 这将完成您想要的操作,尽管我不保证通过几条记录将非常有效。 Enter it as an array formula with Ctrl + Shift + Enter 使用Ctrl + Shift + Enter将其输入为数组公式

{=IF(SUM(--NOT(ISERROR(FIND([table1.Col1],[table2.lookupValue]))))<>1,IF(SUM(--NOT(ISERROR([table1.Col1],[table2.lookupValue]))))>1,"Multiple matches",""),INDEX([table1.Col2],SUM((ROW([table1.Col1])-1)*NOT(ISERROR(FIND([table1.Col1],[table2.lookupValue]))))))}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM