Letter difference between terms

Mavri

New Member
Joined
Nov 30, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone.
Is there any chance for text (or any other)formula that recognize terms that differentiate in only one ore more letters(or words) like in the example bellow
John Smith
Bella Gore
Kessy Lecking
Jon Smith
Jack Apple
Ken Woods
Alena Hay
Bela Gore
Katty Pery
Katy Pery

Concretely is there any chance that excel will extract somehow simmilar terms?

Thanks in advance!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
using your list of names in column X (X2 to X11) to test the below sub

it outputs the matching name in Column Y


VBA Code:
Sub testsoundex()

Dim str As Variant, str1 As Variant
Dim name1 As Variant, name As Variant
Dim nameset1 As Variant, nameset2 As Variant
Dim x As Integer, y As Integer

For x = 2 To 10
For y = x + 1 To 11

nameset1 = Range("X" & x)
nameset2 = Range("X" & y)

str = Left(nameset1, InStr(1, nameset1, " "))
str1 = Mid(nameset1, InStr(1, nameset1, " ") + 1, 50)

name = Soundex(str) & Soundex(str1)

'Debug.Print Soundex(str)
'Debug.Print Soundex(str1)
'Debug.Print name


str = Left(nameset2, InStr(1, nameset2, " "))
str1 = Mid(nameset2, InStr(1, nameset2, " ") + 1, 50)

name1 = Soundex(str) & Soundex(str1)

'Debug.Print Soundex(str)
'Debug.Print Soundex(str1)
'Debug.Print name1
Debug.Print nameset1, nameset2

If name = name1 Then
'Debug.Print "True"
Range("Y" & x) = "Match " & nameset2
Range("Y" & y) = "Match " & nameset1
'Else
'Debug.Print "False"
'Range("Y" & x) = ""
End If

Next y
Next x

End Sub



Function Soundex(varText As Variant) As Variant
On Error GoTo Err_Handler
    'Purpose:   Return Soundex value for the text passed in.
    'Return:    Soundex code, or Null for Error, Null or zero-length string.
    'Argument:  The value to generate the Soundex for.
    'Author:    Allen Browne (allen@allenbrowne.com), November 2007.
    'Algorithm: Based on http://en.wikipedia.org/wiki/Soundex
    Dim strSource As String     'varText as a string.
    Dim strOut As String        'Output string to build up.
    Dim strValue As String      'Value for current character.
    Dim strPriorValue As String 'Value for previous character.
    Dim lngPos As Long          'Position in source string
    
    'Do not process Error, Null, or zero-length strings.
    If Not IsError(varText) Then
        strSource = Trim((varText))
        If strSource <> "" Then
            'Retain the initial character, and process from 2nd.
            strOut = Left(strSource, 1&)
            strPriorValue = SoundexValue(strOut)
            lngPos = 2&
            
            'Examine a character at a time, until we output 4 characters.
            Do
                strValue = SoundexValue(Mid$(strSource, lngPos, 1&))
                'Omit repeating values (except the zero for padding.)
                If ((strValue <> strPriorValue) And (strValue <> vbNullString)) Or (strValue = "0") Then
                    strOut = strOut & strValue
                    strPriorValue = strValue
                End If
                lngPos = lngPos + 1&
            Loop Until Len(strOut) >= 4&
        End If
    End If
    
    'Return the output string, or Null if nothing generated.
    If strOut <> vbNullString Then
        Soundex = strOut
    Else
        Soundex = Null
    End If
    
Exit_Handler:
    Exit Function
    
Err_Handler:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Soundex()"
    'Call LogError(Err.Number, Err.Description, conMod & ".Soundex")
    Resume Exit_Handler
End Function


Private Function SoundexValue(strChar As String) As String
    Select Case strChar
    Case "B", "F", "P", "V"
        SoundexValue = "1"
    Case "C", "G", "J", "K", "Q", "S", "X", "Z"
        SoundexValue = "2"
    Case "D", "T"
        SoundexValue = "3"
    Case "L"
        SoundexValue = "4"
    Case "M", "N"
        SoundexValue = "5"
    Case "R"
        SoundexValue = "6"
    Case vbNullString
        'Pad trailing zeros if no more characters.
        SoundexValue = "0"
    Case Else
        'Return nothing for "A", "E", "H", "I", "O", "U", "W", "Y", non-alpha.
    End Select
End Function
 
Upvote 0

Forum statistics

Threads
1,215,225
Messages
6,123,732
Members
449,116
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top