I have two data sources with street address names, cities, and zips that I'm trying to find which addresses have the highest match percentages and return the maximum value. I have a VBA code that matches two cells strings "Address Compare" but need to compare one address to an entire column.
Please view the VBA code examples attached. One image contains the "Address Compare" used to match two cells while the other code uses a For Loop to index a column and call "Address Compare" module to compare the indexed column with the specific cell.
I cannot figure how to save the matching percentages in an array and return the maximum value. Can I get any help?
Function AddressCompare(first_string As String, Second_string As String, _
Comparing_Letters As Integer) As Double
Dim int_character As Integer, Comparing_LettersMatch As Integer
Dim n_Gram_List1 As String, n_Gram_List2 As String, n_letter_Gram As Variant
Dim n_Gram_array1 As Variant
For int_character = 1 To Len(first_string) - (Comparing_Letters - 1)
If n_Gram_List1 <> "" Then n_Gram_List1 = n_Gram_List1 & ","
n_Gram_List1 = n_Gram_List1 & Mid(first_string, int_character, Comparing_Letters)
Next int_character
For int_character = 1 To Len(Second_string) - (Comparing_Letters - 1)
If n_Gram_List2 <> "" Then n_Gram_List2 = n_Gram_List2 & ","
n_Gram_List2 = n_Gram_List2 & Mid(Second_string, int_character, Comparing_Letters)
Next int_character
n_Gram_array1 = Split(n_Gram_List1, ",")
For Each n_letter_Gram In n_Gram_array1
If InStr(1, n_Gram_List2, n_letter_Gram) Then
Comparing_LettersMatch = Comparing_LettersMatch + 1
End If
Next n_letter_Gram
AddressCompare = Comparing_LettersMatch / (UBound(n_Gram_array1) + 1)
End Function
Function MatchAddyCompare(first_string As String, Arr1rng As Range) As Double
Dim Arr1() As String: Arr1 = Arr1rng.Value
Dim i As Integer
Dim ArrayLen As Integer
Dim MACC() As Variant
ArrayLen = UBound(Arr1) - LBound(Arr1) + 1
For i = 1 To ArrayLen
Call AddressCompare(first_string, Arr1(i), 2)
'MACC(i) = AddressCompare
Next i
'MatchAddyCompare = AddressCompare
End Function
I've added a second message so everyone can see that if I directly compare two cells with "AddressCompare" function, I get a 81% match which is great. However, I need a code that can run the one cell versus the entire column and return the highest percent match. 
