jb
Member
Hello helpers,
I have following code to concatenate multiple cells based on condition.
I have range of cells from b17 to p17 having some text. I have a word in A26. I am searching A26 in b17 to p17 and if match is found then corresponding cells from b16 to p16 will be concatenated with : as separator. This formula works fine if content of a26 is available in b17 to p17 with exact match. But my problem is the word in a26 may be available in b17 to p17 as partial string. I an unable to modify below code to match a26 partially in b17 to p17. please help.
=ConcatenateIf($B$17:$P$17, A26, $B$16:$P$16, " : ")
for e.g a26 has word PP and some cells between b17 to p17 may contain word PP or PP / RT or YP / PP / RT.
>>> use code - tags <<<
I have following code to concatenate multiple cells based on condition.
I have range of cells from b17 to p17 having some text. I have a word in A26. I am searching A26 in b17 to p17 and if match is found then corresponding cells from b16 to p16 will be concatenated with : as separator. This formula works fine if content of a26 is available in b17 to p17 with exact match. But my problem is the word in a26 may be available in b17 to p17 as partial string. I an unable to modify below code to match a26 partially in b17 to p17. please help.
=ConcatenateIf($B$17:$P$17, A26, $B$16:$P$16, " : ")
for e.g a26 has word PP and some cells between b17 to p17 may contain word PP or PP / RT or YP / PP / RT.
>>> use code - tags <<<
Code:
Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = " : ") As Variant
'Updateby Extendoffice
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
Last edited by a moderator: