Multiple Find/Replace VBA

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182

<colgroup><col style="text-align: center;"><col style="text-align: center;"><col span="2" style="text-align: center;"><col style="text-align: center;"></colgroup><tbody></tbody>
ABCD
1StringBadWordGoodWord
2baseballhckeyhockey
3hockeybasebllbaseball
4I love hckeyftballfootball
5ftball is lame

<tbody>
</tbody>

The code below corrects words that are in String; if BadWord is present, it replaces it with GoodWord

My problem is: It only works on a single value where I need it to look in the string.

Example: ("B3") Hockey was corrected
("B4") Hockey wasnt corrected because it was in a string. I need it to correct in a string



Sub vba_find_replace()
Dim myList, myRange As Range


Set myList = Sheets("sheet1").Range("D1:E11") 'two column range with find/replace pairs
Set myRange = Sheets("sheet1").Range("B1:B99") 'range to be searched and replace


For Each cel In myList.Columns(1).Cells
myRange.Replace What:=cel.Value, Replacement:=cel.Offset(0, 1).Value, LookAt:=xlWhole
Next cel


End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,215,836
Messages
6,127,179
Members
449,368
Latest member
JayHo

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