How to vlookup with wild from lookup range

saudkazia

New Member
Joined
Mar 26, 2013
Messages
3
Hi suppose I have the following data as an example


KB58
KB52
KB69
KB05
KB68
KB04
JY025



<colgroup><col></colgroup><tbody>
</tbody>
and a lookup range as below
KB6130
KB5130
KB2125
KB1120
KB0100
JY025180
JY015140

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


basically I want to be able to add a cell/column in the first data set which will lookup the cell ie KB58 against the lookup range and give the amount if it contains the lookup value in the range. So in this case KB58 should be 130.

I would think this would be really easy to do but for some reason Excel tries to be difficult. I can do a vlookup for exact match so that JY025 and JY015 will be 180 and 140 respectively but the rest seem to give incorrect results (obviously).

I did a google to figure out what to do but didn't find a workable solution without involving convoluted formulas (which were not workable anyway for me) or vba (which I don't want) .

The excel file is an invoice sheet and the amounts in the lookup range would vary depending on customer or shipping etc. so lookup range has to be in a separate sheet

Hope I have been clear, please let me know what I need to give in order to make this easier to answer. Using Excel 2016 but the solution should work with anything over 2007.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Fuzzy matching is actually a pretty complicated topic. Your particular question is not as difficult since you're looking at the left side only, but your lookup isn't sorted. So given your situation, you can try:

ABCDEFG
1ListMatchLookupValue
2KB58130KB6130
3KB52130KB5130
4KB69130KB2125
5KB05100KB1120
6KB68130KB0100
7KB04100JY025180
8JY025180JY015140

<tbody>
</tbody>
Sheet6

Array Formulas
CellFormula
B2{=INDEX($F$2:$F$8,SMALL(IF(LEFT(A2,LEN($E$2:$E$8))=$E$2:$E$8,ROW($E$2:$E$8)-ROW($E$2)+1),1))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
Array Formulas
CellFormula
B2{=INDEX($F$2:$F$8,SMALL(IF(LEFT(A2,LEN($E$2:$E$8))=$E$2:$E$8,ROW($E$2:$E$8)-ROW($E$2)+1),1))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
[/QUOTE]

Perfect!

I don't understand it really especially the last part Row($E$2)

And also why index
 
Upvote 0
It's an array formula, so it looks at a range of values.

LEN($E$2:$E$8) returns an array of the lengths of the values in E2:E8, or {3,3,3,3,3,5,5}.

LEFT(A2,{3,3,3,3,3,5,5}) returns the left part of A2 for that length, or {"KB5","KB5","KB5","KB5","KB5","KB58","KB58"}.

The IF now compares that list against E2:E8, giving results of {FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE}

For the TRUE values, it get the result of ROW($E$2:$E$8)-ROW($E$2)+1. The ROW($E$2:$E$8) returns {2,3,4,5,6,7,8}, but when you include the -ROW($E$2)+1, it turns to {1,2,3,4,5,6,7}, which is an offset into the range instead of a row. So the {FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE} becomes {FALSE,2,FALSE,FALSE,FALSE,FALSE,FALSE}.

The SMALL function finds the smallest value in the array, ignoring non-numeric values, or 2.

Then INDEX($F$2:$F$8,2) returns 130.

Hope this makes sense! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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