Multiple Find/Replace VBA

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
[TABLE="width: 392"]
<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>[/TABLE]
[TABLE="width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]String[/TD]
[TD]BadWord[/TD]
[TD]GoodWord[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]baseball[/TD]
[TD]hckey[/TD]
[TD]hockey[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]hockey[/TD]
[TD]basebll[/TD]
[TD]baseball[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]I love hckey[/TD]
[TD]ftball[/TD]
[TD]football
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD]ftball is lame[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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