Dear ashleyuk1984,
I have found this code, It highlight the text which is not common in the paragraphs but not the text that is common. Do you know how I should modify the code in order to highlight the common text in between the two paragraphs ?
Sub Compare()
If StringCompareHighlight(Range("m1"), Range("o1")) Then
Range("q1").Value = "Match"
Else
Range("q1").Value = "Not Match"
End If
If StringCompareHighlight(Range("m2"), Range("o2")) Then
Range("q2").Value = "Match"
Else
Range("q2").Value = "Not Match"
End If
If StringCompareHighlight(Range("m3"), Range("o3")) Then
Range("q3").Value = "Match"
Else
Range("q3").Value = "Not Match"
End If
End Sub
Function StringCompareHighlight(r1 As Range, r2 As Range) As Boolean
''this function compare the words from 2 strings
''each word is separated by "," and the order of these words does not matter
''return true if matches, False if not match
''changes the format of a word in one string that does not exist in the other string
Dim oMatches As Object, oMatch As Object
Dim r(1 To 2) As Range
Dim i As Integer, bDiff As Boolean, iStart As Integer
Set r(1) = r1
Set r(2) = r2
With CreateObject("vbscript.regexp")
.Pattern = " *(\w+) *(?= .*\|)(?!.*\|.* *\1 *)"
.Global = True
.IgnoreCase = True
For i = 1 To 2
Set oMatches = .Execute(" " & r(i).Text & ",|," & r(3 - i).Text & " ")
For Each oMatch In oMatches
iStart = InStr(oMatch.FirstIndex + 1, r(i).Text, oMatch.submatches(0), vbTextCompare)
With r(i).Characters(Start:=iStart, Length:=Len(oMatch.submatches(0))).Font
.Bold = True
.Size = 14
End With
Next oMatch
If oMatches.Count > 0 Then bDiff = True
Next i
End With
StringCompareHighlight = Not bDiff End Function
Best regards