简体   繁体   中英

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:

Keyword Category
 EE     Telecommunications
 Water  Utilities
Amazon  Internet Transaction

On a separate worksheet, I have another table (Table2) of transactions. 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). 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).

I have tried INDEX/MATCH and SEARCH combinations, and I've been researching for hours. I'm pretty sure I need to use an {array} formula, but I just cannot get it right.

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.

Table2 needs to look something like this:

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

{=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]))))))}

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