You could do this with a User Defined Function (UDF). Put the UDF into a code module and then reference it in a cell just like you would any other Excel worksheet function. Using your example, where test value is in column A and values to be concatenated are in column B, this should work as a UDF:
Code:
Private Function BuildLongList(TestValue As Variant)
Dim LC As Long
Application.Volatile
Do While LC <= Range("A" & Rows.Count).End(xlUp).Row
If Range("A1").Offset(LC, 0) = TestValue Then
BuildLongList = BuildLongList & Range("B1").Offset(LC, 0) & ", "
End If
LC = LC + 1
Loop
If Right(BuildLongList, 2) = ", " Then
BuildLongList = Left(BuildLongList, Len(BuildLongList) - 2)
End If
End Function
Then in the cell(s) where you want the results to show up you would put formula similar to these, first example for any cell other than A1 or B1 in row 1, and second for any cell other than A9 or B9 in row 9:
- =BuildLongList(A1)
- =BuildLongList(A9)
Bookmarks