Concatenate cell data into another data if values matches

You could probably use a User Defined Function (aka UDF) for this. Put this into a module sheet.

Public Function conditional_concat_strs(rSTRs As Range, rCRITs As Range, rCRIT As Range, Optional sDELIM As String = ", ")
    Dim c As Long, sTMP As String

    Set rSTRs = rSTRs.Cells(1, 1).Resize(rCRITs.Rows.Count, rCRITs.Columns.Count)
    For c = 1 To rCRITs.Cells.Count
        If rCRITs(c).Value2 = rCRIT Then _
            sTMP = sTMP & rSTRs(c).Value & sDELIM
    Next c
    conditional_concat_strs = Left(sTMP, Application.Max(Len(sTMP) - Len(sDELIM), 0))
End Function

Use like any native worksheet function.

      Concatenate Strings by criteria

Leave a Comment