Reverse Wildcard Vlookup

Alohadboy

New Member
Joined
Mar 18, 2011
Messages
26
Hello - this site was a huge help in the last problem I was faced with so I thought I would try again.

I have 2 columns of data as such, one that contains various site names ("Site") and the other to contain a Code. I want to populate the "Code" column using the Legend below:
Site_____________Code
Seattle Trans
Idaho Plant
Nevada Trans
Portland Admin

I have a "Code" legend set up as such:
Trans 100
Plant 300
Admin 500
etc...

I need a formula that I can enter into the "Code" column above that will return the value from the legend. Ex, any cell that contains the word "trans" would populate the column with "100", etc. Obviously there is a massive list and a more exhaustive legend so a formula is the answer.

I have tried both of the following formulas with no luck:
=VLOOKUP("*"&B5&"*", $J$5:$K$12, 2, 0) = where B5 is the "site" above and $J$5:$K$12 is the "legend".
=VLOOKUP(B5, "*"&$J$5:$K$12&"*", 2, 0)

Any help is appreciated. Thanks.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
To retrieve the text after the space, which you can then build into your VLOOKUP function, use:
RIGHT(B5,LEN(B5)-FIND(" ",B5))
 
Upvote 0
Hello - this site was a huge help in the last problem I was faced with so I thought I would try again.

I have 2 columns of data as such, one that contains various site names ("Site") and the other to contain a Code. I want to populate the "Code" column using the Legend below:
Site_____________Code
Seattle Trans
Idaho Plant
Nevada Trans
Portland Admin

I have a "Code" legend set up as such:
Trans 100
Plant 300
Admin 500
etc...

I need a formula that I can enter into the "Code" column above that will return the value from the legend. Ex, any cell that contains the word "trans" would populate the column with "100", etc. Obviously there is a massive list and a more exhaustive legend so a formula is the answer.

I have tried both of the following formulas with no luck:
=VLOOKUP("*"&B5&"*", $J$5:$K$12, 2, 0) = where B5 is the "site" above and $J$5:$K$12 is the "legend".
=VLOOKUP(B5, "*"&$J$5:$K$12&"*", 2, 0)

Any help is appreciated. Thanks.
One way...

Book1
ABCDE
2Seattle Trans100_Trans100
3Idaho Plant300_Plant300
4Nevada Trans100_Admin500
5Portland Admin500___
Sheet1

Formula entered in B2 and copied down:

=LOOKUP(1E100,SEARCH(D$2:D$4,A2),E$2:E$4)
 
Upvote 0
One way...

Sheet1

<table style="font-family:Verdana,Arial; font-size:10pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; " border="0" cellpadding="0" cellspacing="0"> <colgroup><col style="font-weight:bold; width:30px; "><col style="width:106px;"><col style="width:72px;"><col style="width:29px;"><col style="width:72px;"><col style="width:72px;"></colgroup><tbody><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td> </td><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">2</td><td style="text-align:center; border-style:solid; border-width:1px; border-color:#000000; ">Seattle Trans</td><td style="text-align:center; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">100</td><td style="color:#ffffff; text-align:center; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td><td style="text-align:center; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">Trans</td><td style="text-align:center; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">100</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">3</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-width:1px; border-color:#000000; ">Idaho Plant</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">300</td><td style="color:#ffffff; text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">Plant</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">300</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">4</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-width:1px; border-color:#000000; ">Nevada Trans</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">100</td><td style="color:#ffffff; text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">Admin</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">500</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">5</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-width:1px; border-color:#000000; ">Portland Admin</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">500</td><td style="color:#ffffff; text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td><td style="color:#ffffff; text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td><td style="color:#ffffff; text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">_</td></tr></tbody></table>


Formula entered in B2 and copied down:

=LOOKUP(1E100,SEARCH(D$2:D$4,A2),E$2:E$4)

Valko, this worked. Thank you. Can you shed some light on what the "1E100" is? Thanks.
 
Upvote 0
Valko, this worked. Thank you. Can you shed some light on what the "1E100" is? Thanks.
1E100 is scientific notation for a very large number, 1 followed by 100 zeros.

The SEARCH function will return either an error (no match was found) or a number from 1 to 32,767.

For the formula to work correctly we need a lookup value, 1E100, that is greater than or equal to 32,767.

I use 1E100 because it's greater than or equal to 32,767 and it's easy to remember.
 
Upvote 0
Valko, thanks for the help. I have a similar question (don't know if I need to start another thread or not) and couldn't figure it out.

Using the same format with 2 columns of data as such, one that contains various site names ("Site") and the other to contain a State ID #. I want to populate the "ID" column using the Legend below:
Site_____________ID
Seattle Trans
Houston Plant
Nevada Trans
Portland Admin

I have a "ID" legend set up as such:
State______ID___City 1___City 2___City 3 etc.
Washington _02__ Seattle__ Aberdeen__ Blaine__ etc
Texas ______03 __El Paso__ Dallas___ Houston__ etc
etc...

As I populate the legend with different cities out to the right I want the corresponding legend "ID" to populate in the "ID" field next to the "Site" column in the top chart. Ex, Seattle Trans would have an "02" in the ID column and Houston Plant would have an "03" (as would anything else out to the right of "Texas").

I tried to modify the formula you provided but I guess it only works if your lookup info is in one column or row.

Thanks again.
 
Upvote 0
Valko, thanks for the help. I have a similar question (don't know if I need to start another thread or not) and couldn't figure it out.

Using the same format with 2 columns of data as such, one that contains various site names ("Site") and the other to contain a State ID #. I want to populate the "ID" column using the Legend below:
Site_____________ID
Seattle Trans
Houston Plant
Nevada Trans
Portland Admin

I have a "ID" legend set up as such:
State______ID___City 1___City 2___City 3 etc.
Washington _02__ Seattle__ Aberdeen__ Blaine__ etc
Texas ______03 __El Paso__ Dallas___ Houston__ etc
etc...

As I populate the legend with different cities out to the right I want the corresponding legend "ID" to populate in the "ID" field next to the "Site" column in the top chart. Ex, Seattle Trans would have an "02" in the ID column and Houston Plant would have an "03" (as would anything else out to the right of "Texas").

I tried to modify the formula you provided but I guess it only works if your lookup info is in one column or row.

Thanks again.
I think I would extract the city name to its own cell like this:

Book1
ABC
2Seattle TransSeattle2
3Houston PlantHouston3
4Nevada TransNevada_
5Portland AdminPortland4
6McKees Rocks AdminMcKees Rocks6
7Sault Ste. Marie PlantSault Ste. Marie5
Sheet2

Those 2 and 3 word city names can cause problems!

Book1
ABCDE
10StateIDCity 1City 2City 3
11Washington2SeattleAberdeenBlaine
12Texas3El PasoDallasHouston
13Maine4Portland__
14Michigan5DetroitSault Ste. Marie_
15Pennsylvania6PittsbughMcKees Rocks_
Sheet2

This formula entered in B2 and copied down to extract the city name:

=LEFT(A2,FIND("^",SUBSTITUTE(A2," ","^",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))))-1)

This array formula** entered in C2 and copied down to return the ID:

=IF(COUNTIF(C$11:E$15,B2),INDEX(B$11:B$15,MAX(IF(C$11:E$15=B2,ROW(C$11:E$15)-ROW(C$11)+1))),"")

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
Hi, I found this formula is very useful. =LOOKUP(1E100,SEARCH(D$2:D$4,A2),E$2:E$4)
This formula result is searching text, if available anywhere in A2. But I need the result, only if it is beginning of text in A2 cell. Help me for modification.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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