Below is a UDF (stored in a Module in VBE)
'below compares words in two strings and generates a % similarity - unique words in 2nd string are searched for within 1st string
Function CompareString(rngS1 As Range, rngS2 As Range, Optional boolCase As Boolean = True)
Dim vW1, vW2, oDic As Object, lngW As Long, lngU As Long, lngM As Long, strTemp As String
vW1 = Split(rngS1, " ")
vW2 = Split(rngS2, " ")
Set oDic = CreateObject("Scripting.Dictionary")
For lngW = LBound(vW2) To UBound(vW2) Step 1
strTemp = Replace(vW2(lngW), ".", "")
With oDic
If Not .exists(strTemp) Then
lngU = lngU + 1
.Add strTemp, lngU
If boolCase Then
lngM = lngM + rngS1.Parent.Evaluate("SUMPRODUCT(--ISNUMBER(FIND("" " & strTemp & " "","" ""&SUBSTITUTE(" & rngS1.Address & ",""."","""")&"" "")))")
Else
lngM = lngM - IsNumeric(Application.Match(strTemp, vW1, 0))
End If
End If
End With
Next lngW
Set oDic = Nothing
CompareString = lngM / lngU
End Function
called from a cell along the lines of:
compares B1 to A1 - in this case returning 67%
(case sensitivity is optional)
Modify as appropriate.
Bookmarks