Hi
You could try this UDF.
Use it as
=CONCATIFS($C$2:$C$50,", ",$A$2:$A$50,F$1)
or
=CONCATIFS($C$2:$C$50,", ",$A$2:$A$50,F$1,$B$2:$B$50,$E2)
Code:Option Explicit Function CONCATIFS(ByVal ConcatCol As Variant, ByVal Delim As String, ParamArray ParamA() As Variant) As String '//ParamA=each pair should be Criteria range followed by it's criteria Dim lngLoopC As Long Dim lngLoopR As Long Dim lngLoop As Long Dim lngCount As Long Dim lngCounter As Long Dim lngIndex As Long Dim lngCase As Long Dim varOP() As Variant Dim strMatch As String Dim blnTranspose As Boolean If TypeOf ConcatCol Is Range Then If ConcatCol.Columns.Count > 1 And ConcatCol.Rows.Count = 1 Then blnTranspose = True ConcatCol = Application.Transpose(Application.Transpose(ConcatCol.Value2)) ElseIf ConcatCol.Columns.Count = 1 And ConcatCol.Rows.Count > 1 Then ConcatCol = Application.Transpose(ConcatCol.Value2) End If End If For lngLoop = LBound(ParamA) To UBound(ParamA) If TypeOf ParamA(lngLoop) Is Range Then If blnTranspose Then ParamA(lngLoop) = Application.Transpose(Application.Transpose(ParamA(lngLoop).Value2)) Else ParamA(lngLoop) = Application.Transpose(ParamA(lngLoop).Value2) End If End If Next ReDim varOP(1 To UBound(ConcatCol)) lngCount = (1 + UBound(ParamA)) \ 2 For lngLoopR = LBound(ConcatCol) To UBound(ConcatCol) lngCounter = 0 For lngLoopC = LBound(ParamA) To UBound(ParamA) Step 2 If LCase(ParamA(lngLoopC)(lngLoopR)) = LCase(ParamA(lngLoopC + 1)) Then lngCounter = lngCounter + 1 End If Next If lngCount = lngCounter Then If Len(Trim(ConcatCol(lngLoopR))) Then If InStr(1, strMatch & "|", "|" & ConcatCol(lngLoopR) & "|", lngCase) = 0 Then lngIndex = lngIndex + 1 varOP(lngIndex) = ConcatCol(lngLoopR) strMatch = strMatch & "|" & ConcatCol(lngLoopR) End If End If End If Next If lngIndex Then ReDim Preserve varOP(1 To lngIndex) CONCATIFS = Join(varOP, Delim) End If End Function




Reply With Quote
Bookmarks