hi guys. im tryign to compare addresses on column A vs column B and needs to show what is the percentage of similarity. this is my code so far, one sheet called CM, sheet2 called ABC, sheet 3 called MATCH copy both to here and show percentage. my code is below but im not sure why something completely different show a big % of similarity. see attached image and code. ty guys.
[TABLE="width: 344"]
<tbody>[TR]
[TD][TABLE="width: 344"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 344"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
<strike></strike>
[TABLE="width: 344"]
<tbody>[TR]
[TD][TABLE="width: 344"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 344"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
<strike></strike>
Code:
Application.ScreenUpdating = False
LR = Sheets("CM").Cells(Rows.Count, 1).End(xlUp).Row
With Sheets("MATCH")
.Range("B1:B" & LR).Value = Sheets("CM").Range("B1:B" & LR).Value
.Range("C1:C" & LR).Value = Sheets("ABC").Range("B1:B" & LR).Value
.Range("A1:A" & LR).Value = Sheets("CM").Range("A1:A" & LR).Value
For r = 2 To LR
If Trim(.Cells(r, "A").Value) = Trim(.Cells(r, "B").Value) Then
.Cells(r, "C").Value = 1
GoTo Done
End If
Str1 = Trim(.Cells(r, "B").Value)
Str2 = Trim(.Cells(r, "C").Value)
Len1 = Len(Str1)
Len2 = Len(Str2)
Same = 0
For c = 1 To Len2
If InStr(1, Str1, Mid(Str2, c, 1), 1) Then
Same = Same + 1
Str1 = Replace(Str1, Mid(Str2, c, 1), "*", 1, 1)
End If
Next c
.Cells(r, "D").Value = Same / Len1
Done:
Next r
End With
Application.ScreenUpdating = True