Crossmatching Names All Possible Match VBA

austinandreikurt

Board Regular
Joined
Aug 25, 2020
Messages
91
Office Version
  1. 2016
Platform
  1. Windows
Hi,
Is there a vba code where it can replicate the google search or facebook search function that can list all possible results including misspellings? Say I have all the names in Column A, then my search value is in D1, then all possible results will be listed down in Column F. Below is my example.

Book1
ABCDEF
1NamesSEARCHRoseAnn DomingoRoseAnn Domingo
2RoseAnn DomingoRose Ann Domingo
3Juan Dela VegaRose Domingo
4Rose Ann DomingoRose Anne Domingo
5Rose DomingoRose Ann Domngo
6Rose Anne Domingo
7Tina Jacob
8Rose Ann Domngo
9Chris White
10Alex Domingo
11Rose Peñaflor
12
Sheet1
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
austin let's get the ball rolling. Now this usually gets more questions than answers, but we have to start some place. The requirement for this program is the first 4 letters of the name have to be the same. Let us know if this doesn't work for you.

VBA Code:
Sub Prog1()

Dim LastRow As Integer
Dim Nam As String
Dim Row1 As Integer

Row1 = 1

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For i = 2 To LastRow
    Nam = Left(Cells(i, 1), 4)
If Left(Cells(i, 1), 4) Like Left(Cells(1, 4), 4) Then
    Cells(Row1, 6) = Cells(i, 1)
    Row1 = Row1 + 1
End If

Next i

End Sub
 
Upvote 0
Hi @Ezguy4u thank you for attending my query. Is it possible to also consider the last name? Also, there are instances when lastname, first name format in a column just like below. The green ones are the one that should be captured by the codes:

Book1
ABCDEF
1NamesSEARCHAlexandre ReyesAlexandre Mark Reyes
2Alexandre Mark ReyesAlex Reyes
3Alex ReyesAlexndre Reyes
4Alexndre ReyesReyes, Alexandre
5Rose Domingo
6Rose Anne Domingo
7Tina Jacob
8Rose Ann Domngo
9Chris White
10Alex Domingo
11Rose Peñaflor
12Rse Domingo
13Reyes, Alexandre
Sheet1
 
Upvote 0
austin Coming up with a solution to excel questions is always a challenge. The different requirements, as we think of them, just means we keep working at it. Now I came up with a new input data requirement. As you can see if we can separate the name it will help with the output. So if you have any more requirements just let us know.

1662183637670.png


VBA Code:
Sub Prog2()

Dim LastRow As Integer
Dim Nam As String
Dim Nam2 As String
Dim Row1 As Integer

Row1 = 1

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
 Nam = Left(Cells(2, 4), 4)
 Nam2 = Left(Cells(2, 6), 4)
  
For i = 2 To LastRow
 
If Nam Like Left(Cells(i, 1), 4) Then
    Cells(Row1, 8) = Cells(i, 1)
    Row1 = Row1 + 1
ElseIf Nam2 Like Left(Cells(i, 1), 4) Then
    Cells(Row1, 8) = Cells(i, 1)
    Row1 = Row1 + 1
End If

Next i

End Sub
 
Upvote 0
Hi @Ezguy4u sorry I only replied now as I got sick. Many thanks for attending this problem and almost there! It still captures the "Alex Domingo" where "Domingo" is too far from the Key Last Name "Reyes".
 
Upvote 0
austin, I love this. Coming up with a solution to an excel problem is so much fun. Now what we have here is a leaky boat. I keep patching up the holes as they appear. But I can imagine a couple more holes appearing in the future maybe. If you watch how the input data is entered and correct the data before they spring a leak, no problem. But if you think of something else and really want to come up with a fix, let us know.

VBA Code:
Sub Prog2()

Dim LastRow As Integer
Dim NamCnt1 As Integer
Dim NamCnt2 As Integer
Dim NamCnt3 As Integer
Dim NamCnt4 As Integer
Dim NamCnt5 As Integer
Dim Nam1 As String
Dim Nam2 As String
Dim Row1 As Integer

Row1 = 1

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

NamCnt1 = Len(Cells(2, 4)) 'First Name
NamCnt2 = Len(Cells(2, 6))  'Last Name
 
For i = 2 To LastRow

NamCnt3 = Len(Cells(i, 1)) 'how many characters in cell
NamCnt4 = (NamCnt3 - NamCnt2) + 1 'This works for the first name first
Nam1 = Mid(Cells(i, 1), NamCnt4, NamCnt2)

NamCnt5 = NamCnt3 - NamCnt1
Nam2 = Mid(Cells(i, 1), NamCnt2 + 3, NamCnt1)
   
If Left(Cells(2, 4), 4) Like Left(Cells(i, 1), 4) And Left(Cells(2, 6), 4) Like Left(Nam1, 4) Then
    Cells(Row1, 8) = Cells(i, 1)
    Row1 = Row1 + 1
ElseIf Left(Cells(2, 6), 4) Like Left(Cells(i, 1), 4) And Left(Cells(2, 4), 4) Like Left(Nam2, 4) Then
    Cells(Row1, 8) = Cells(i, 1)
    Row1 = Row1 + 1
End If

Next i

End Sub

NamesFirst NameMiddle NameLast NameAlexandre Mark Reyes
Alexandre Mark ReyesSEARCHAlexandre ReyesAlex Reyes
Alex ReyesAlexndre Reyes
Alexndre ReyesReyes, Alexandre
Rose DomingoReyes, Alexandre
Rose Anne Domingo
Reyes, Alexandre
Rose Ann Domngo
Chris White
Alex Domingo
Rose Peñaflor
Rse Domingo
Reyes, Alexandre
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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