Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lucille Holmes   on Mar 05 In MS Office Category.

  
Question Answered By: Olga Allen   on Mar 05

I agree that a Soundex routine is closer to what you
specified, but here is a function  that compares 2
strings and returns a percent (a double) indicating
how similar they are.

Public Function Str_Comp(st1 As String, st2 As String)
As Double
'From Analyzing Business Data with Excel, O'Reilly
Media
Dim MtchTbl(100, 100)
Dim MyMax As Double, ThisMax As Double
Dim i As Integer, j As Integer, ii As Integer, jj
As Integer
st1$ =
Trim(Application.WorksheetFunction.Proper(st1$))
st2$ =
Trim(Application.WorksheetFunction.Proper(st2$))
MyMax# = 0
For i% = Len(st1$) To 1 Step -1
For j% = Len(st2$) To 1 Step -1
If Mid(st1$, i%, 1) = Mid(st2$, j%, 1)
Then
ThisMax# = 0
For ii% = (i% + 1) To Len(st1$)
For jj% = (j% + 1) To Len(st2$)
If MtchTbl(ii%, jj%) >
ThisMax# Then
ThisMax# = MtchTbl(ii%,
jj%)
End If
Next jj%
Next ii%
MtchTbl(i%, j%) = ThisMax# + 1
If (ThisMax# + 1) > ThisMax# Then
MyMax# = ThisMax# + 1
End If
End If
Next j%
Next i%
Str_Comp# = MyMax# / ((Len(st1$) + Len(st2$)) / 2)
End Function

I have had good results with this function.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Help with VBA function checksum Or get search suggestion and latest updates.


Tagged: