VBA MS Excel ConcatIF Function
Since long time I have been thinking to have a function in Excel like SUMIF. Initially I thought Office 2010 will bring this feature/function. But now I have solution function here for all.
VBA Code
Public Function ConcatIf(ByRef FindInRange As Range, ByRef FindText As String, ByRef StringRange As Range, Optional ByRef strDelimiter As String)
If IsNull(strDelimiter) Then strDelimiter = ","
Dim l As Integer
Dim result As String
For l = 1 To FindInRange.Count
If FindInRange(l, 1) = FindText Then
If IsNull(result) Or Trim(result) = "" Then
result = StringRange(l, 1)
Else
If StringRange(l, 1) "" Then result = result & strDelimiter & StringRange(l, 1)
End If
End If
Next
ConcatIf2 = CStr(result)
End Function