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>
A | B | C | D | |
1 | String | BadWord | GoodWord | |
2 | baseball | hckey | hockey | |
3 | hockey | basebll | baseball | |
4 | I love hckey | ftball | football | |
5 | ftball 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