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
<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