Skip to content

Instantly share code, notes, and snippets.

@willjobs
Last active January 31, 2021 02:22
Show Gist options
  • Save willjobs/b86a760d945b9e22a40dca7f7f17ad48 to your computer and use it in GitHub Desktop.
Save willjobs/b86a760d945b9e22a40dca7f7f17ad48 to your computer and use it in GitHub Desktop.
Custom Excel Functions to compare two strings
Public Function countDifferences(str1 As String, str2 As String) As Integer
Dim i As Integer
If Len(str1) <> Len(str2) Then
countDifferences = -1
Exit Function
End If
countDifferences = 0
For i = 1 To Len(str1)
If Mid(str1, i, 1) <> Mid(str2, i, 1) Then
countDifferences = countDifferences + 1
End If
Next i
End Function
Public Function findDifferences(str1 As String, str2 As String) As String
Dim i As Integer
If Len(str1) <> Len(str2) Then
findDifferences = "error"
Exit Function
End If
findDifferences = ""
For i = 1 To Len(str1)
If Mid(str1, i, 1) <> Mid(str2, i, 1) Then
If Len(findDifferences) > 0 Then
findDifferences = findDifferences & ","
End If
findDifferences = findDifferences & Str(i)
End If
Next i
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment