VLOOKUP where the the Lookup Value is longer than the value it searches

CaptainCsaba

Board Regular
Joined
Dec 8, 2017
Messages
78
Hey Everyone!

So here is the thing. We get a report that we have to use and every row contains a 6 digit code and there is random gibberish before and after it and it is never the same. We have a list of these codes with what they mean and I want to create a VLOOKUP macro for it. The problem is as you can see is that we can't search only by the code because of the gibberish. An example:

M1RE76 NAB ACF MLCI WMP EQ 76
CBNY-M1SAGE MLCI WMP EQ 38

What we have in our excel is: M1RE76 and M1SAGE (not all beginwith M1. Some begin with EQ or WM so there is no real logic to them)

There are around 300 of these and what we need in VLOOKUP is "M1RE76" and "M1SAGE". They are never in the same place in the report we get. For now they all only begin with letters but the can end in numbers. I don't really know how I can exact the codes and the use VLOOKUP to make our job much easier. What makes it harder is that not all the report is made up of these, so for example we get 100 rows and around 15 are like this.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi, welcome to the board.

This is do-able IF you can come up with some logic for accurately identifying the required codes.
If, as you say, "there is no real logic to them" then it's going to be impossible.

Remember - there doesn't have to be only one rule - there might be several rules that we can work with - for example, all are 6 digits long, may begin with M1 or EQ or WM, and so on.
 
Upvote 0
Hi, welcome from me also!

Is it something like this?


Excel 2013/2016
ABCDE
1CodeFormulaLookupReturn
2M1RE76 NAB ACF MLCI WMP EQ 76CK123456A
3CBNY-M1SAGE MLCI WMP EQ 38EZ123456B
4M1RE76C
5G123457D
6M1SAGEE
Sheet1
Cell Formulas
RangeFormula
B2=LOOKUP(1,-SEARCH($D$2:$D$6,A2),$E$2:$E$6)
 
Upvote 0
It is more like this:

This a part of what we get, as you can see, the required codes are sorrounded by other text and besides this we get many other things that don't have this code.

CBNY-T.A. WLD EX U.S CR EQ PRT DFA
2,944,191CBNY-INT CR EQ PRT DFA INV DM GR IN
346,401CBNY-INT LARGE CAP GR PT OF DFAIDG
143,823CBNY-INT SOC CORE EQ PORT/DFAIDG
43,714CBNY-INTL HIGH REL PROF DFA INV
225,324CBNY-INTL SUSTAINABILITY 1 PORTFOL
2,398CBNY-JCF GBL ADAP CAP PRES FD
669CBNY-JCF GLB ADAP MLT ASSET FD
309,582CBNY-JHF II INTL SEA FD
123,778CBNY-JOHN HANCOCK FUNDS
669,467CBNY-LEGAL AND GEN COLL INV TRST
284,730CBNY-ADMNGE MLCI WMP EQ 75
75,665CBNY-M1GSTR NAB ACF JANA MMGST
76,203CBNY-BLKGLF MLCI WMP EQ 74
60,484CBNY-ALALGE MLCI WMP EQ 76
31,118CBNY-M1REGD NAB ACF MLCI WMP EQ 2
652,430CBNY-CXBIGE CBU WUK EQ 18
68,131CBNY-CBMSGE MLCI WMP EQ 38
219,177CBNY-M1SSJP MLCI JANA PASSV
351,760CBNY-NATIONAL FINANCIAL SERVICES LL
99,778CBNY-SDA INTL EQUITY INDEX FUND
1,129,550CBNY-SIEFORE BANAMEX BASICA 3
1,227,790CBNY-SIEFORE BANAMEX BASICA 4
982,215CBNY-SIEFOREBANAMEXBASICA2 SADECV
2,528CBNY-STIFEL NICOLAUS SEG ACCT EBOC
517,943CBNY-T.A. WLD EX U.S CR EQ PRT DFA

<colgroup><col><col></colgroup><tbody>
</tbody>

<colgroup><col><col></colgroup><tbody>
</tbody>

We have another excel file that basically looks like this:

ADMNGE XYZ Company
M1GSTR ABC Company
BLKGLF KLF Company

So we get that confusing report and somebody had already researched what the codes mean we want the company names to appear in the report excel inn the next colums after VLOOKup looks it up it the other excel file.

<tbody>
</tbody>
 
Upvote 0
Can you use this?
=LOOKUP(99^99,SEARCH($C$1:$C$5,"*"&A1&"*"),$D$1:$D$5)

<tbody>
</tbody>

M1RE76 NAB ACF MLCI WMP EQCK123456A
CBNY-M1SAGE MLCI WMP 28EZ123456B
M1RE76C
G123457D
M1SAGEE

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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