multi value lookup using offset etc

whitbybob

New Member
Joined
Aug 4, 2011
Messages
3
I have a workbook with two sheets
first sheet "P1" has
A B
1 Item Code
2 A1 Toy
3 A1 dress
4 A1 Mop
5 B1 Toy
6 B1 dress
7 B1 Mop
8 B1 house
Second sheet "Ug" has unique list of Items and should look like this
A B
1 Count 7
2 Item Code1 Code2 Code3 Code4
3 A1 Toy dress Mop
4 B1 Toy dress Mop house
The formula in B1 is =MATCH(REPT("z",40),'P1'!A:A)-(CELL("Row",A2)-1)
The formula in b3 is =IF(LEN(Ug!$B$1),VLOOKUP(A3,OFFSET('P1'!$A$1,0,0,Ug!$B$1,2),2,0),"")
The formula in c3 is
=IF(COUNTIF(OFFSET('P1'!$A$1,0,0,Ug!$B$1,1),$A3)>COUNTA($B3:B3),INDEX(OFFSET('P1'!$B$1,MATCH(B3,OFFSET('P1'!$B$1,0,0,Ug!$B$1,1),0),0,Ug!$B$1,1),MATCH($A3,OFFSET('P1'!$A$1,MATCH(B3,OFFSET('P1'!$B$1,0,0,Ug!$B$1,1),0),0,Ug!$B$1,1),0)),"")
The formula in d3 is copied from c3
=IF(COUNTIF(OFFSET('P1'!$A$1,0,0,Ug!$B$1,1),$A3)>COUNTA($B3:C3),INDEX(OFFSET('P1'!$B$1,MATCH(C3,OFFSET('P1'!$B$1,0,0,Ug!$B$1,1),0),0,$B$1,1),MATCH($A3,OFFSET('P1'!$A$1,MATCH(C3,OFFSET('P1'!$B$1,0,0,Ug!$B$1,1),0),0,Ug!$B$1,1),0)),"")

If I then copy down cells b3:d3 to line 4 I should get the values shown, but instead I get Toy Toy Toy Toy Toy

I believe this happens because the Match uses "0" as the match type allowing it to find any of the occurrences.
A look at my 800 line table shows some working correctly and others not correct.

Is there a way to fix this?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about describing in English what it is that you are trying to achieve?
 
Upvote 0
So I am trying to get a cross list of the rows. This will let me see that customer A1 bought Toy Dress and Mop.
Keep in mind that there are over 8000 lines in the real P1 sheet, and anywhere from 1 to 100 items per customer, so easier to see how the products are bought by a single customer line in the Ug sheet.
 
Upvote 0
As a temporary fix, I added a series of fields calculating the row of each customer line in P1 then used that number for an Index lookup that gave me the desired results but not in a nice way.
 
Upvote 0
If you want a crosstab type of analysis, how about using a PivotTable?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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