If Cell contains string, then vlookup result

balki

New Member
Joined
May 17, 2011
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hey folks,
I searched for an answer on this, but maybe didn't know how to word it properly.

In my case below, I'm trying to create a rule set (Green table) when if the value is contained in the "Description" column of the main table, then a lookup will auto-classify the row based on the type. I hope that makes sense. I've dummied up the data below.
Ex. the first data row contains "Canadian Tire", therefore the type is "HomeStuff". The second line contains "Park", and is therefore "Parking", etc. The last one has no match, so it returns "Unknown".
Help? I feel like this should be easier than I'm making it, but I can't figure this one out for some reason.
Thank you all!

1650643769002.png
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
i have not copied all your sample as its an image

But try

=INDEX($I$2:$I$4,MATCH("*"&H2&"*",$B$2:$B$4,0))
adjust the range to suite your data

but, is there a chance the keyword maybe within a word , but you dont want
as this is looking for
ANYTHING first , then PARK and then anything gain
so it maybe part of word and so we may need to include space


Book3
ABCDEFGHI
1resultkeywordtype
2fred john happry park 1parkingparkparking
3fred john happry stuff 2foodstufffood
4fred john happry candian tyre 3homecandian tyrehome
Sheet1
Cell Formulas
RangeFormula
D2:D4D2=INDEX($I$2:$I$4,MATCH("*"&H2&"*",$B$2:$B$4,0))



Note: Images are difficult to see , and also requires that I input all the data myself, which is very time consuming.

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC , then put the sample spreadsheet onto a share
I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
 
Upvote 0
Thank you ETAF... I'm sorry for the format in my original post. I have a work computer that is totally locked down.
I've attached a dummied up file to Google Drive below, and inserted your formula. It's close, but is doing some strange things to the first line, and subsequent lines where there are no matches.

A littler fine tuning perhaps?
Google Shared File

I really appreciate your support, thank you again!
-Balki
 
Upvote 0
sorry, made an error
try
=IF(INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0))=0,"unknown",INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0)))

why alcohol ? you have LCBO in table
BUT LCRO in text

LookupTest (1).xlsx
ABCDEFGHIJKL
1DateDescription DR CR TotalAutoTypeExpect to see:Key WordType
24/14/22Point of Sale - Interac RETAIL PURCHASE CANADIAN TIRE S3.96- 3.96 Vehicle VehicleLCBOAlcohol
34/14/22Point of Sale - Interac RETAIL PURCHASE MILLENNIUM PARK12.00- 12.00 Parking ParkingParkParking
44/14/22Point of Sale - Interac RETAIL PURCHASE STUFF'D14.71- 14.71 Food FoodStuffFood
54/14/22Point of Sale - Interac RETAIL PURCHASE TOY SHOP OF PET85.83- 85.83 unknown UnknownCanadian TireVehicle
64/14/22Point of Sale - Interac RETAIL PURCHASE TOY SHOP OF PET71.17- 71.17 unknown Unknownshop of
74/14/22Point of Sale - Interac RETAIL PURCHASE SAM'S PLACE17.87- 17.87 unknown Unknown
84/14/22Amazon.ca*1O1 AMAZON.CA, ON13.32- 13.32 unknown Unknown
94/14/22LCRO/RAO Purchase25.00- 25.00 unknown Alcohol
104/14/22Amazon.ca*1T2 AMAZON.CA, ON10.55- 10.55 unknown Unknown
11
Master
Cell Formulas
RangeFormula
E2:E10E2=[@CR]-[@DR]
F2:F10F2=IF(INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0))=0,"unknown",INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0)))
C5C5=(15.98+29.99+29.99)*1.13
C6C6=157-C5
 
Upvote 0
Solution
A couple of questions:
  1. Is it possible that more than one of the key words could appear in a cell? (eg "Point of Sale - Interac RETAIL PURCHASE PARK STUFF") If so, what should happen?
  2. Are you sure that you mean "contains string" per your title, not "contains word"? For example "Point of Sale - Interac RETAIL PURCHASE Red Parker" would be classified as "Parking"?

I also suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

1650777374260.png
 
Upvote 0
sorry, made an error
try
=IF(INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0))=0,"unknown",INDEX($L$2:$L$10,MATCH(1,COUNTIF(B2,"*"&$K$2:$K$10&"*"),0)))

why alcohol ? you have LCBO in table
BUT LCRO in text
Brilliant! Works like a charm. I am rather happy that it isn't as easy as a solution as I was worried it would be. I consider myself fairly competent in excel and this one definitely had me stumped. I'm going to spend some time interrogating this formula so I can pull it apart and understand exactly what it's doing now that I know it works. Thank you so much! Really, really appreciate the effort and support!
Thank you!

(Oh, and P.S. LCRO was just a typo when I was dummying up data - good catch! :-) I must have been drinking the alcohol in question?! ha ha)
 
Upvote 0
you are welcome
be aware though as mentioned
but, is there a chance the keyword maybe within a word , but you dont want
as this is looking for
ANYTHING first , then PARK and then anything gain
so it maybe part of word and so we may need to include space
and by Peter_SSs
A couple of questions:
  1. Is it possible that more than one of the key words could appear in a cell? (eg "Point of Sale - Interac RETAIL PURCHASE PARK STUFF") If so, what should happen?
  2. Are you sure that you mean "contains string" per your title, not "contains word"? For example "Point of Sale - Interac RETAIL PURCHASE Red Parker" would be classified as "Parking"?
 
Upvote 0
A couple of questions:
  1. Is it possible that more than one of the key words could appear in a cell? (eg "Point of Sale - Interac RETAIL PURCHASE PARK STUFF") If so, what should happen?
  2. Are you sure that you mean "contains string" per your title, not "contains word"? For example "Point of Sale - Interac RETAIL PURCHASE Red Parker" would be classified as "Parking"?

I also suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

View attachment 63102
Thank you Peter! I've updated my profile, thanks for the hint there!
To answer your questions:
1. If both words were in the cell, I would just ask the user to expand on the "key word" to be more specific. I'm not overly worried about the frequency of this happening, as the data shows that there are a ton of entries, but the majority are repeats, minus transaction codes that are often embedded in the middle of the overall string of text. If this auto-populates 75% of the records, and the user needs to manually enter the last 25%, that will be a total win.
2. I am hoping this will work with a string, as there 'may' be some entries where "park" is many different parking lots, so it could read "Balki's Parking Garage" or "Balki Park and Ride", or "Balki FindParkAndGo". If the rules don't tweeze it out properly, then key words may need to be adapted to be more specific as mentioned in question 1 above.

Like I say, I'm really just try to make this incrementally better than it was, which it now is, so I'm super happy. In a few months, I may come back with my hat in my hands looking for something to narrow things down more, but I'll cross that bridge then. Thanks again for the help and suggestions! :-)
 
Upvote 0
Thanks for the clarifications & for updating your profile. (y)

Since you have MS 365 and your data appears to be in a formal Excel table, you might consider this adaptation. With it, if there are multiple keywords (eg row7), then the formula will list all the relevant types.

I would also make the lookup table into a formal Excel table (if it isn't already). That way, formulas will automatically expand/contract ranges if the lookup values get added to or deleted from.
I have named that table as tblLookup
Then use this modified formula using the table nomenclature.

balki LookupTest.xlsx
ABCDEFGHI
1DateDescription DR CR AutoTypeKey WordType
214/04/2022Point of Sale - Interac RETAIL PURCHASE CANADIAN TIRE S3.96 Vehicle LCBOAlcohol
314/04/2022Point of Sale - Interac RETAIL PURCHASE MILLENNIUM PARK12.00 Parking ParkParking
414/04/2022Point of Sale - Interac RETAIL PURCHASE STUFF'D14.71 Food StuffFood
514/04/2022Point of Sale - Interac RETAIL PURCHASE TOY SHOP OF PET85.83 Unknown Canadian TireVehicle
614/04/2022Amazon.ca*1O1 AMAZON.CA, ON13.32 Unknown
714/04/2022LCRO/RAO/LCBO Purchase - Big Park Stuff25.00 Alcohol, Parking, Food
814/04/2022Amazon.ca*1T2 AMAZON.CA, ON10.55 Unknown
9
10
Sheet1
Cell Formulas
RangeFormula
E2:E8E2=TEXTJOIN(", ",1,FILTER(tblLookup[Type],ISNUMBER(SEARCH(tblLookup[Key Word],[@Description])),"Unknown"))
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top