How to do a lookup based on a sub string of what is in a cell?

How to do a lookup based on a sub string of what is in a cell?


I have a Transactions table, with transactions in the first column. I want to group them into Vendors by somehow matching/looking up a substring of them to values in the Vendors table. I think I need a wildcard expression (or Regex) in the lookup somehow.


I have this


and a lookup table


and I want to create this


I've tried using wildcards, but not been able to get it to work. Any help or suggestion would be welcome.. Exact/specific syntax would be perfect!

MacBook Air (M3, 2024)

Posted on Dec 15, 2025 9:46 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 15, 2025 3:20 PM

This is possible using a regular expression.


First, you have to combine all your potential vendors into a list, which you can do via TEXTJOIN() function:


=TEXTJOIN("|",TRUE,Vendors::A)


Will result in something like:


Aldi|Boots|Marks and Spencer


(the | character is used by regular expressions to separate parts of the query).


This can then be passed into REGEX.EXTRACT() to perform the search. In cell B2, set the formula to:


=REGEX.EXTRACT(A,TEXTJOIN("|",1,Vendors::A),1)


This will look at the values in the Transaction column (column A) of this table, and run a regular expression comparison using the list of vendors extracted via TEXTJOIN()


5 replies
Question marked as Top-ranking reply

Dec 15, 2025 3:20 PM in response to DMBKeisha

This is possible using a regular expression.


First, you have to combine all your potential vendors into a list, which you can do via TEXTJOIN() function:


=TEXTJOIN("|",TRUE,Vendors::A)


Will result in something like:


Aldi|Boots|Marks and Spencer


(the | character is used by regular expressions to separate parts of the query).


This can then be passed into REGEX.EXTRACT() to perform the search. In cell B2, set the formula to:


=REGEX.EXTRACT(A,TEXTJOIN("|",1,Vendors::A),1)


This will look at the values in the Transaction column (column A) of this table, and run a regular expression comparison using the list of vendors extracted via TEXTJOIN()


Dec 16, 2025 8:28 AM in response to DMBKeisha

Just be aware that the results might not be perfect. You might get false hits. It will take more work to reduce/eliminate the false hits. For example, "aldi" will return a hit for any string that contains the letters "aldi" in that order, such as "Scalding pot from Walmart". Instead of searching for "aldi", you would need to search for "^aldi | aldi | aldi$" to find "aldi" as a separate word at the beginning, within, or end of the string. And same for the other vendors. If you add a new column to the Vendor table, you can create these search strings for each of your vendors and use that column in the TEXTJOIN instead of column A. You can hide the new column after it is all set up.


formula in B2 ="^"&A2&" | "&A2&" | "&A2&"$"


Of course, you can still have problems if your transactions have things like "Boots from Walmart" because it won't be able to tell if the vendor is Boots or Walmart. A solution to that is to include the string "from " three times in the formula given above so the search will be "from Walmart" not just "Walmart".


Another and much easier solution to all that is to have all of your transactions end in "from vendor" so all you have to do is search for " from vendor$". The formula in B2 would then be =" from "&A2"&"$"

Dec 16, 2025 8:42 AM in response to Camelot

Thanks for the quick reply. Very interesting solution. I've tried it on a small Transaction table with a small Vendor table, and it works fine.


My real Transaction table has 7000+ records and my Vendor Table has 800+ records. I'll give it a try shortly. Hopefully it wont run out of memory (I know I should really be doing this in a relational database !!)

How to do a lookup based on a sub string of what is in a cell?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.