Try this then.
Add this UDF to your VB editor (Alt+F11, Insert|Module)
and then paste:
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
Then keep formula in D2 of Sheet 1, copied down.
You don't need the formula in column E
Then In C2 of Sheet2 enter formula:
=SUBSTITUTE(TRIM(aconcat(IF(Sheet1!$D$2:$D$7=B2&"^"&A2,Sheet1!$C$2:$C$7,"")," "))," ",",")
confirm it with CTRL+SHIFT+ENTER not just ENTER and copy it down the column.
Bookmarks