Find/Replace Loop

cle44024

New Member
Joined
Sep 17, 2015
Messages
9
Hello,
I have a list of correctly spelled names in Column A.
I have a list of incorrectly spelled names in Column B.
The names between Column A and Column B are correlated.
The incorrectly spelled version of the name is also in multiple cells on the same worksheet.
I would like to create a macro that can do a find/replace of all the incorrectly spelled names in column B with the correctly spelled names in column B.

Here is an example
Column A:
A1= Smith
A2= Jones
...
A100= Johnson

Column B:
B1= Smiith
B2= Jons
...
B100= Jonson


Can someone please provide code for a Macro that I could run that would simply find all the contents of the cell in B1 on a given sheet, then do a replace-all with the contents of the cell in A1...then loop for the next 100, or 1000, or whatever the need may be.
Thanks
 
Last edited:
Code:
Sub replaceNames()

    Dim target As Worksheet
    Dim source As Worksheet
    
    Set target = ThisWorkbook.Sheets("Data")
    Set source = ThisWorkbook.Sheets("Map")
    
    With source
        For x = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
        
            target.Cells.Replace What:=.Cells(x, 2), Replacement:=.Cells(x, 1), LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Next x
    End With
End Sub

The sheet with the data is called "Data" and the sheet with the misspelled names relating to correctly spelled names is called "Map".
 
Upvote 0

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