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
 
this is very cool. amazing udf and amazing formula.

thanks Aladin.

Sheet1, A:E, houses the data...

201
Black
White
202
Black
Grey
203
White
Grey
401
Black
Grey
Red
Blue
402
White
Yellow
Blue
Grey

<tbody>
</tbody>

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

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

<tbody>
</tbody>

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

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
The following formula works great. However, I have more 'codes' than the four shown in this example. I have as many as 2,000. Is there a way to make the formula shorter and still work?

=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)),"")
 
Upvote 0
The following formula works great. However, I have more 'codes' than the four shown in this example. I have as many as 2,000. Is there a way to make the formula shorter and still work?

=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)),"")

Do you have the TEXTJOIN function on your system? If not, is it possible for you to use a vba function like ACONCAT which is shown in this very thread?
 
Upvote 0

Forum statistics

Threads
1,216,150
Messages
6,129,154
Members
449,488
Latest member
qh017

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