Vlookup with Duplicates

John Col

Board Regular
Joined
Aug 19, 2015
Messages
67
Dear All,

I am struggling with a formula for a week now and really would like to find a solution to this problem. I have read a lot of forums/websites and did not found the solution yet

It is relative easy to explain:

Raw data is
-----------Column 1-----------Column 2

Row 1--------------20------------------2
Row 2--------------80------------------4
Row 3--------------60------------------3
Row 4--------------50------------------5
Row 5--------------50------------------8
Row 6-------------100-----------------10

Below, I sort column 1 from low to high with the SMALL function. The question is how to have the same values in column 2 as in the raw data.
I can not use a standard vlookup function because it will display two times a "5" in column 2 because of raw 2 and 3 has a value 50 .

New data is
------------Column 1--------Column 2--------I need to have in column 2 the values > as in the raw data

Row 1--------------20---------------- ?--------------2 This is the outcome I am looking for
Row 2--------------50-------------- --?--------------5 This is the outcome I am looking for
Row 3--------------50-----------------?--------------8 This is the outcome I am looking for
Row 4--------------60-----------------?--------------3 This is the outcome I am looking for
Row 5--------------80-----------------?--------------4 This is the outcome I am looking for
Row 6-------------100-----------------?-------------10 This is the outcome I am looking for

Thank you very very very much.

Hope someone have the solution to this problem .

Best wishes,
John Cole
 
Dear AlanY :),

It is only a small question to unstand the formula.
{=INDEX($B$1:$B$7,SMALL(IF($A$2:$A$7=D2,ROW($A$2:$A$7)),COUNTIF(D$2:D2,D2)))}
As you can see the INDEX start at =INDEX($B$1 (an empty cell) > why is it not =INDEX($B$2. It only works when it starts at this $B$1 as you did.

Best wishes,
John

ok, I see.

=INDEX($B$1:$B$11 .. is to get the row reference when a match is found.
e.g. if the second 50 is found in A10 as in post#9, =INDEX($B$1:$B$11 will look at Col B and row 10 for the matched data.

hope this help
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
of course, you can change the index ref, to start at B3 in this example


Excel 2012
ABCDE
1
2
3
4
5Raw DataNew Data
6202202
7804505
8603508
9505603
10508804
111001010010
2



Excel 2012
E
62
2
Cell Formulas
RangeFormula
E6{=INDEX($B$3:$B$11,SMALL(IF($A$6:$A$11=D6,ROW($A$6:$A$11)-2),COUNTIF(D$6:D6,D6)))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Excel 2010
ABCDE
110191019
28011202
3202204
4603208
5208505
6505603
7100608011
820410010
91001010060
Sheet3
Cell Formulas
RangeFormula
E1{=SMALL(IF(A$1:A$9=D1,B$1:B$9),COUNTIF(D$1:D1,D1))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Dear AlanY

Many thanks again. Much appreciated.
I get it, you use a correction with the -2 to index the correct cells.

Thumbs up.
Best wishes,
John
 
Upvote 0
Excel 2010
ABCDE
110191019
28011202
3202204
4603208
5208505
6505603
7100608011
820410010
91001010060

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Array Formulas
CellFormula
E1{=SMALL(IF(A$1:A$9=D1,B$1:B$9),COUNTIF(D$1:D1,D1))}

<thead>
</thead><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>

Dear Mr LlozdFinancials,

Thanks a lot. Seems great. Also nice that you put column E in the right order. I already did this with a far too difficult formula.... :p . This is much easier. What I mean is when for example there is 3 times a 20, (like in your example) it will put the numbers 2,4 and 8 in the correct order. I do not know whether you did this on purpose but I like it.
Many thanks.

Best wishes,
John Col
 
Upvote 0
Excel 2010
ABCDE
101900
28011202
3202204
4603208
5208505
6505603
7100608011
820410010

<tbody>
</tbody>


Dear Mr Lloydfinancials,

Actually there is one problem with your formula.
When for example cell A1 = 0 and you delete row 9 it will turn into two times a 0 which is not true.
What i mean is that the values are not flexible when there are no values in row for example row 9.


Best wishes,
John
 
Upvote 0
Thank you for pointing that out John. This should take care of it:
=SMALL(IF(INDIRECT("A$1:A$" &COUNTA(A:A))=D1,INDIRECT("B$1:B$" & COUNTA(A:A))),COUNTIF(D$1:D1,D1))
Luke
 
Upvote 0
Thank you for pointing that out John. This should take care of it:
=SMALL(IF(INDIRECT("A$1:A$" &COUNTA(A:A))=D1,INDIRECT("B$1:B$" & COUNTA(A:A))),COUNTIF(D$1:D1,D1))
Luke

Dear Luke,

Really nice, thumps up.
How many years you needed to gain so much experience?
In contrast, I was thinking I know a lot about exel but spending 2 days on this forum decreased my believe of this a lot .

Best wishes,
John
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,003
Members
449,480
Latest member
yesitisasport

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