Search for exact string and return lookup value

JayB0730

Board Regular
Joined
Oct 22, 2014
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hello,

This has been racking my brain and my original formulas are pulling in the wrong values. Here is what I'd like to do...

  • I have two Excel Tables; Table 1 where all my data exists. I would like to have a formula to determine if CATEGORY = A then I want to check if any LOOKUP words ( WHOLE WORDS ONLY) are found in the teh description--if so, return Table 2's SUB-CAT
  • If not, just return "888".
  • I need to lookup whole words so that in the example of "GI Joe", Sub-cat returns "789" because it found GI vs. "456" and ignoring "G"


Table 1

DESCRIPTIONCATEGORYSUB-CAT
GI JoeA789
I Love CoffeeAShould return error to indicate no words found in description is found in Table 2 Lookup Words (this will alert me to add in the future)
pizza is greatA000
Help Me!C888

<tbody>
</tbody>


Table 2
LOOKUP WordsSUB CAT
Basketball123
G456
GI789
PIZZA000

<tbody>
</tbody>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
How about:


Book1
ABC
1Table 1
2
3DESCRIPTIONCATEGORYSUB-CAT
4GI JoeA789
5I Love CoffeeANo words found
6pizza is greatA0
7Help Me!C888
8
9
10
11Table 2
12LOOKUP WordsSUB CAT
13Basketball123
14G456
15GI789
16PIZZA0
Sheet4
Cell Formulas
RangeFormula
C4=IF(B4="A",IFERROR(LOOKUP(2^15,SEARCH(" "&$A$13:$A$16&" "," "&A4&" "),$B$13:$B$16),"No words found"),888)
 
Upvote 0
How about:

ABC
1Table 1
2
3DESCRIPTIONCATEGORYSUB-CAT
4GI JoeA789
5I Love CoffeeANo words found
6pizza is greatA0
7Help Me!C888
8
9
10
11Table 2
12LOOKUP WordsSUB CAT
13Basketball123
14G456
15GI789
16PIZZA0

<tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
C4=IF(B4="A",IFERROR(LOOKUP(2^15,SEARCH(" "&$A$13:$A$16&" "," "&A4&" "),$B$13:$B$16),"No words found"),888)

<tbody>
</tbody>

<tbody>
</tbody>

Hi Eric,

Thanks for your response! I'm interested in understanding the breakdown of your formula, specifically 2^15 --- What does this represent in this formula. I did the following and wondering if it would work out the same way? I created a helper column that normalized the DESCRIPTION Data. Formula I used was:

Worksheet Formulas
CellFormula
HELPER CELL=LOWER(
TRIM(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
SUBSTITUTE(
DESCRIPTION CELL,
"("," "),
")"," "),
"-"," "),
":"," "),
";"," "),
"!"," "),
","," "),
"."," ")))

<tbody>
</tbody>

Then, in the SUB-CAT field I used the following formula:

Worksheet Formulas
CellFormula
SUB-CAT=IF([@[CATEGORY]]="A",INDEX('LookupSheet.xlsx'!CATEGORY[CAT],MATCH(TRUE,ISNUMBER(SEARCH(" "&LookupSheet.xlsx'!CATEGORY[Categories]&" ",[@HELPER])),0)),[@[CATEGORY]])

<tbody>
</tbody>
 
Upvote 0
Well, let me explain how the LOOKUP part of the formula works, since it's a bit opaque. LOOKUP has some array processing functionality, so in the interior part, where it has this: " "&$A$13:$A$16&" " it creates an internal array. It has each of the words from A13:A16, plus it appends a space before and after, so you get this: {" Basketball "," G "," GI "," PIZZA "}. Now the SEARCH tries to find each of those words in " "&A4&" ". I put spaces before and after everything so that G would not match GI. So after all 4 SEARCHes have been done, the array looks like {#VALUE !,#VALUE !,1,#VALUE !} because only GI was found. So now we are trying to look up 2^15 from that array. The way LOOKUP works is, first, it ignores error values. Next, if it cannot find a match, it will return the last numerical value, or 1. SEARCH returns the position within the text where the search value is found. Since the maximum length of a text in a cell is 32768, if we search for 32768 (or 2^15 in exponential notation), we should get the matching position, or 3. Then LOOKUP returns the value from the second range $B$13:$B$16 in the # 3 position.

Hope that makes sense! I haven't actually tested your formula, but it seems it should work. The main difference is that in case of multiple matches, my formula will return the last match, and I believe yours will return the first match.
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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