Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant

Dim xResult As String

Dim i as integer

On Error Resume Next

If CriteriaRange.Count <> ConcatenateRange.Count Then

ConcatenateIf = CVErr(xlErrRef)

Exit Function

End If

For i = 1 To CriteriaRange.Count

If CriteriaRange.Cells(i).Value = Condition Then

xResult = xResult & Separator & ConcatenateRange.Cells(i).Value

End If

Next i

If xResult <> "" Then

xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)

End If

ConcatenateIf = xResult

Exit Function

End Function

then in my cell my formula is

=CONCATENATEIF($A$2:$A$15, D2, $B$2:$B$15, ",")