Index & Match, Concatenate multiple results

joetabush

New Member
Joined
Aug 28, 2007
Messages
3
I've got a decent background on VLOOKUP & CONCATENATE, but apparently those 2 fall short of exactly what I'm looking to do... (I'm pretty sure I need Index & Match, but I'm not doing a good job of teaching myself...)

Sheet1 contains a table of 'color packs' (table below shows A1:E6. Column A is the Color Code ('201'), and Columns B:E are the colors in each pack... max of 4)

(columns) A B C D E
201 Black White (empty cell) (empty cell)
202 Black Grey (empty cell) (empty cell)
203 White Grey (empty cell) (empty cell)
401 Black Grey Red Blue
402 White Yellow Blue Grey


In Sheet2, I am looking to list all colors in column A, and use a CONCATENATE (or similar) to string together all the packs in which that Color appears.
Example:

Column A Column B
Black 201, 202, 401
White 201, 203, 402
Grey 202, 203, 401, 402
Red 401
Blue 401, 402
Yellow 402


Thank you in advance!!
-Joe
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Maybe this array formula (use Ctrl+Shift+Enter and not only Enter):

Code:
=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),COLUMNS($B2:B2))),"")

Markmzz
 
Upvote 0
Thanks but no good.... Returns only one result, not multiple results...

Maybe this array formula (use Ctrl+Shift+Enter and not only Enter):

Code:
=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),COLUMNS($B2:B2))),"")

Markmzz
 
Upvote 0
Thanks but no good.... Returns only one result, not multiple results...

Here is the result:

A B C D E
Color Cod01 Cod02 Cod03 Cod04
Black 201 202 401
White 201 203 402
Grey 202 203 401 402
Red 401
Blue 401 402
Yellow 402

Did you press Ctrl+Shift+Enter?

Markmzz
 
Upvote 0
As Markzz mentioned,

Use curl brackets,


Excel 2007
ABCDE
1ABCDE
2Black201202401201,202,401
Sheet2
Cell Formulas
RangeFormula
E2=B2&","&C2&","&D2
B2{=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),COLUMNS($B2:B2))),"-")}
C2{=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),COLUMNS($B2:C2))),"-")}
D2{=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),COLUMNS($B2:D2))),"-")}
Press CTRL+SHIFT+ENTER to enter array formulas.


Muz.
 
Upvote 0
Sheet1, A:E, houses the data...

[TABLE="width: 240"]
<colgroup><col style="width: 48pt;" span="5" width="64"> <tbody>[TR]
[TD="class: xl63, width: 64, bgcolor: transparent"] [/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"] [/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"] [/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"] [/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]201[/TD]
[TD="class: xl63, bgcolor: transparent"]Black[/TD]
[TD="class: xl63, bgcolor: transparent"]White[/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]202[/TD]
[TD="class: xl63, bgcolor: transparent"]Black[/TD]
[TD="class: xl63, bgcolor: transparent"]Grey[/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]203[/TD]
[TD="class: xl63, bgcolor: transparent"]White[/TD]
[TD="class: xl63, bgcolor: transparent"]Grey[/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]401[/TD]
[TD="class: xl63, bgcolor: transparent"]Black[/TD]
[TD="class: xl63, bgcolor: transparent"]Grey[/TD]
[TD="class: xl63, bgcolor: transparent"]Red[/TD]
[TD="class: xl63, bgcolor: transparent"]Blue[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]402[/TD]
[TD="class: xl63, bgcolor: transparent"]White[/TD]
[TD="class: xl63, bgcolor: transparent"]Yellow[/TD]
[TD="class: xl63, bgcolor: transparent"]Blue[/TD]
[TD="class: xl63, bgcolor: transparent"]Grey[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[TD="class: xl63, bgcolor: transparent"] [/TD]
[/TR]
</tbody>[/TABLE]

Sheet2, A:B, houses the processing...

[TABLE="width: 201"]
<colgroup><col style="width: 48pt;" width="64"> <col style="width: 153pt; mso-width-source: userset; mso-width-alt: 7253;" width="204"> <tbody>[TR]
[TD="class: xl65, width: 64, bgcolor: transparent"] [/TD]
[TD="class: xl65, width: 204, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]Black[/TD]
[TD="class: xl65, bgcolor: transparent"]201, 202, 401[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]White[/TD]
[TD="class: xl65, bgcolor: transparent"]201, 203, 402[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]Grey[/TD]
[TD="class: xl65, bgcolor: transparent"]202, 203, 401, 402[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]Red[/TD]
[TD="class: xl65, bgcolor: transparent"]401[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]Blue[/TD]
[TD="class: xl65, bgcolor: transparent"]401, 402[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]Yellow[/TD]
[TD="class: xl65, bgcolor: transparent"]402[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[/TR]
</tbody>[/TABLE]

First, add the following code as a module to your workbook using Alt+F11...

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function

Now invoke on Sheet2...

B2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=REPLACE(aconcat(IF(FREQUENCY(IF(Sheet1!$A$2:$A$6<>"",
  IF(Sheet1!$B$2:$E$6=$A2,MATCH(Sheet1!$A$2:$A$6,Sheet1!$A$2:$A$6,0))),
  ROW(Sheet1!$A$2:$A$6)-ROW(Sheet1!$A$2)+1),", "&Sheet1!$A$2:$A$6,"")),1,2,"")
 
Upvote 0
Column A Column B
Black 201, 202, 401
White 201, 203, 402
Grey 202, 203, 401, 402
Red 401
Blue 401, 402
Yellow 402


Thank you in advance!!
-Joe

Sorry,

I didn't notice the commas (thanks Aladin).

Try this array formula (use Ctrl+Shift+Enter and not only Enter):

Code:
=IFERROR(INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),1)),"")&
IFERROR(", "&INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),2)),"")&
IFERROR(", "&INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),3)),"")&
IFERROR(", "&INDEX(Sheet1!$A$2:$A$6,SMALL(IF(Sheet1!$B$2:$E$6=$A2,ROW(Sheet1!$B$2:$B$6)-ROW(Sheet1!$B$2)+1),4)),"")

Now, the results:

Code:
Color	Codes
Black	201, 202, 401
White	201, 203, 402
Grey	202, 203, 401, 402
Red	401
Blue	401, 402
Yellow	402

Markmzz
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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