Compare Two Columns of Names That Are Not Exact in Format and Copy Entire Row of Matches to New Sheet

Lee1234

New Member
Joined
Mar 24, 2011
Messages
1
Hi - I am new to this forum. I have a MS Excel macro question. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I need to compare two columns of names (on different sheets, within the same workbook) and copy the entire row of data for the matches to a new sheet. The names in both of these columns are the same individuals. However, some of the names in these columns are in a slightly different format. Example:
Column1/Sheet1 = Smith, James
Column1/Sheet2 = Smith, James W.
<o:p></o:p>
Is there any way that I can either do a wildcard type search (i.e.: "like" or "contains")? <o:p></o:p>
<o:p></o:p>
Or how can I search on lastname, and then firstname only (so that initials are not factored into the search)? I know I can do this via a vLookup instead of a macro, but I have a lot of names and also would like to add this as part of other steps in a macro. <o:p></o:p>

<o:p>Currently, the code I have works well for exact matches. But, it will not return the names where the formatting does not match exactly in both columns.</o:p>
<o:p></o:p>
<o:p>------------------------ Current code ---------------------------</o:p>
<o:p>Sub Compare()</o:p>
<o:p>Dim rng As Range
Dim c As Range
Dim cfind As Range</o:p>

<o:p>On Error Resume Next</o:p>
<o:p>Set rng = Worksheet("Sheet1").Range("A2", Worksheet("Sheet1").Range("A65536").End(xlUp))
For Each c In rng
Set cfind = Worksheet("Sheet2").Range("A2", Worksheet("Sheet2").Range("A65536").End(xlUp)).Find _
(what:=c.Value, lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If cfind Is Nothing Then
c.EntireRow.Copy Worksheets("Final").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
Set cfind = Nothing
End If

Next c
Set rng = Nothing</o:p>

<o:p>Application.CutCopyMode = False</o:p>
<o:p>End Sub</o:p>
<o:p>--------------------------------------------------------------------</o:p>

Thank you for any assistance!<o:p></o:p>!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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