Here's my version
In cell E2
=IF(C1<>C2,GetMaxCommon(B2,$B$2:$C$51,C2,FALSE),"")
Then fill down to the bottom of the table
Function GetMaxCommon(ByVal txt As String, rng As Range _
, myGroup As Long, CSense As Boolean) As String
Dim r As Range, x, i As Long, temp As String, m As Object, Pos As Long, n As Long
Static RegX As Object
If RegX Is Nothing Then
Set RegX = CreateObject("VBScript.RegExp")
RegX.IgnoreCase = Not CSense
End If
x = Split(txt)
Pos = UBound(x)
For Each r In rng.Columns(1).Cells
If (r.Value <> txt) * (r(, 2).Value = myGroup) Then
temp = r.Value
With RegX
For i = 0 To UBound(x)
.Pattern = x(i)
If .test(temp) Then
Set m = .Execute(temp)(0)
If m.FirstIndex <> 0 Then
n = i - 1
Exit For
Else
temp = Trim(Mid$(temp, m.Length + 1))
End If
Else
n = i - 1
Exit For
End If
Next
If Pos > n Then Pos = n
End With
End If
Next
ReDim Preserve x(Pos)
GetMaxCommon = Join$(x)
End Function
Remove Variation With Function.xlsm
Bookmarks