striderider
New Member
- Joined
- Jul 10, 2017
- Messages
- 2
Hi everyone,
I am trying to build a formula that uses multiple IF statements to concatenate. This is the formula I'm using for ConcatenateIF but I want to be able to add multiple IF conditions to it.
Any suggestions? Thanks in advance
I am trying to build a formula that uses multiple IF statements to concatenate. This is the formula I'm using for ConcatenateIF but I want to be able to add multiple IF conditions to it.
Any suggestions? Thanks in advance
Code:
Function Concatenateif(CriteriaRange As Range, condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant'Update 20150414
Dim xResult As String
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