multiple replacement macro

k.03a

New Member
Joined
Jul 12, 2011
Messages
19
Hi all,

I am looking for a way to replace a large number of text values in the whole workbook with other text values?

In a very large excel file, I have a list of 1000 European towns which I want to replace by a list of 1000 US towns. I have a table with the corresponding towns as below:
Europe US
London New York
Paris Los Angeles
etc...

Is there a macro that can be written to replace all values in the workbook corresponding to A2 by B2, A3 by C3, A4 by C4 etc...?

Many thanks for your help !
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Here's one way to do it:

First have the lists like this on one sheet:
Excel Workbook
AB
1EUROPEUS
2LondonNew York
3ParisLos Angeles
Sheet

Then paste this code to your VBA module:
Code:
Sub ReplaceCityNames()

Dim c As Range
Dim Europe As Range
Dim WS As Worksheet
Dim ListSheet As Worksheet

Set ListSheet = Sheets("Sheet3")    'The sheet where the Europe - US lists are found

With ListSheet
    Set Europe = .Range(.Range("A2"), .Range("A" & .Rows.Count).End(xlUp))  'Just the A column
End With

For Each c In Europe    'Loops through the cities in the list
    For Each WS In Worksheets
    'Doesn't replace the cities on the ListSheet (= the original city list remains unchanged)
        If WS.Name <> ListSheet.Name Then
            WS.Cells.Replace What:=c.Value, Replacement:=c.Offset(0, 1).Value, LookAt:=xlPart, _
                    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                    ReplaceFormat:=False
        End If
    Next WS
Next c

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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