Last active
January 31, 2021 02:22
-
-
Save willjobs/b86a760d945b9e22a40dca7f7f17ad48 to your computer and use it in GitHub Desktop.
Custom Excel Functions to compare two strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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