---A---- ----------B---------- C ---D--- -------------------E-------------------
1 Raw Data Summary
2 Name Comments Name Comments
3 Tom Amazing!! Peter I don't know anything
4 Harry I knew it.. Harry I knew it..
5 Peter Rob
6 Tom Where are you? Tom Amazing!!; Where are you?; I am outside
7 Tom I am outside
8 Peter I don't know anything
9 Rob
The formula in E2 and copied down, which MUST be confirmed with Ctrl+Shift+Enter rather than just Enter, is
=CatIf(($A$3:$A$9=D3)*($B$3:$B$9<>""), $B$3:$B$9, "; ")
Function CatIf(avbIf As Variant, _
rInp As Range, _
Optional sSep As String = ",") As String
' shg 2007
' Catenates the elements of vInp separated by sSep
Dim iRow As Long
Dim iCol As Long
Dim i As Long
On Error Resume Next
i = UBound(avbIf, 2)
If Err.Number Then
' avbIf is 1D
For iRow = 1 To rInp.Rows.Count
For iCol = 1 To rInp.Columns.Count
i = i + 1
If avbIf(i) Then CatIf = CatIf & rInp(iRow, iCol) & sSep
Next iCol
Next iRow
Else
' it's 2D
For iRow = 1 To rInp.Rows.Count
For iCol = 1 To rInp.Columns.Count
If avbIf(iRow, iCol) Then CatIf = CatIf & rInp(iRow, iCol) & sSep
Next iCol
Next iRow
End If
If Len(CatIf) Then CatIf = Left(CatIf, Len(CatIf) - Len(sSep))
End Function
Bookmarks