Handling duplicated values with VLookup or similar?

izzywhizzy

New Member
Joined
Sep 7, 2018
Messages
2
Hi,

I have two excel sheets and need to lookup data in one and return a value from the other, however there is a complication which I haven't been able to solve so far.

Sheet one has Item Code in col A.
Sheet two also has Item Code in Col A, and Location in Col B.
In both sheets there may be duplicate Item Codes on many rows, but all Locations are unique.

Sheet One

ITEM CODELOCATION
001
001
245
288
600
600

<tbody>
</tbody>

Sheet Two

CODELOCATION
001A
001B
001C
245D
245E
288F

<tbody>
</tbody>

I need to lookup each Item Code listed in sheet one, and if it is found in sheet two then return the Location from sheet two, into sheet one.
This works fine with a simple VLookup where there is only one unique Item Code. However, where there are duplicate Item Codes, the same Location is returned for all rows, whereas I need all the different Locations to be returned.


Data I wish to have returned into Sheet one:



ITEM CODELOCATION
001A
001B
245D
288F
600
600

<tbody>
</tbody>


Using the example data above, when looking up Item Code 001 it should return Locations A and B each on different lines, where VLookup is returning Location A and A.
** I do NOT need Location C to be returned as there is not a third instance of the Item Code 001 to match it against.
** I DO need the Locations to be returned in the order found, working down the sheet.

When looking up Item Code 245 it should return only D (being the first Location found for that Item Code).
When looking up Item Code 288, it should return F.
When looking up Item Code 600 nothing will be returned.

As you can see, the Item Code data is not the same in each Sheet and the number of duplicated Item Codes varies.


Thanks in advance for any advice.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
In B2 of Sheet1 control+shift+enter, not just enter, and copy down:

=IFERROR(INDEX(Sheet2!$B$2:$B$7,SMALL(IF(Sheet2!$A$2:$A$7=$A2,ROW(Sheet2!$A$2:$B$7)-ROW(INDEX(Sheet2!$A$2:$B$7,1,1))+1),COUNTIFS($A$2:A2,A2))),"")
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,306
Members
449,218
Latest member
Excel Master

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