Given a sheet like so:
Sheet 1
Product Name
-----------------
Fancy Shoes
Plain Shoes
Comfy Slippers
Nice Loafers
Pressed Shirt
Tee Shirt
Collared Button-Up
and a sheet of wildcards:
Sheet 2
Product Wildcard | Product Category
---------------------------------------
*Shirt | Shirt
*Button-Up | Shirt
*Shoes | Shoes
*Loafers | Shoes
*Slippers | Shoes
I'm hoping to produce the following:
Product Name | Product Category
----------------------------------------
Fancy Shoes | Shoes
Plain Shoes | Shoes
Comfy Slippers | Shoes
Nice Loafers | Shoes
Pressed Shirt | Shirt
Tee Shirt | Shirt
Collared Button-Up | Shirt
In other words, can I lookup a category for a product in Sheet 1 that matches a Product Wildcard in Sheet 2?
I've tried to use VLOOKUP('Sheet 1'!A2, 'Sheet 2'!A2:B6, 2, FALSE)
and MATCH('Sheet 1'!A2, 'Sheet 2'!A2:A6, 0)
. Both give me #N/A. I suspect those functions expect the search text to be the only thing that can be wildcarded and my Product Wildcards are taken literally and not interpreted as wildcards.
I'm wondering if there is another way to do this with built-in Excel functions, or if I'm going to need to write some VBA?
Thanks in advance for help on this!
Based on my reading here (specifically the note at the bottom), this seems to not be possible using
VLOOKUP
alone. If all of your wildcards don't have spaces, you could do it like this: (not an explicit formula, just a list of algorithmic steps)FIND
to get the location of the first space in the reversed version, subtracting that from theLEN
of the string gives you the amount of string before the wildcard bit.RIGHT
to truncate the string to the wildcard, and use that withVLOOKUP
.If there are only two words in each cell and the word that determines the category (ex.: Shoes, Slippers, Shirt, etc...) is always second, you can use the following
INDEX/MATCH
to get the category:The below is an array formula (entered with Ctrl+Shift+Enter):
You can use "Formulas" > "Evaluate Formula" on the cell containing the formula to see how it's working step by step.