I have the code below that corrects spelling mistakes in Col.I on Sheet1 based on criteria in a two column table located at W6:X# on Sheet10.
In column W on Sheet10 each cell has a letter/wildcard combination (eg. c*m*c*n) and next to each of these in adjacent cells there are words in column X (eg. communication) which represent correct spellings.
The cells in Col.I on Sheet1 contain text as phrases, eg. 'his communiccation was very poor'. The words in the phrases will vary in terms of their case, so cases should not be matched during the vba's search and the phrases vary in number of words.
The code below changes misspelt words to the word that corresponds in Sheet10 Column X but only if the word is the only word in the cell.
How can I tailor this code so it finds and corrects words that are part of a phrase in a cell?
It would be an added benefit if any corrected words could be highlighted in bold red so I can easily spot the changes after they've been made (this would be a nice to have but not essential).
Of course please feel free to ask any questions if you need more scoping for this, thanks.
Any help much appreciated.
In column W on Sheet10 each cell has a letter/wildcard combination (eg. c*m*c*n) and next to each of these in adjacent cells there are words in column X (eg. communication) which represent correct spellings.
The cells in Col.I on Sheet1 contain text as phrases, eg. 'his communiccation was very poor'. The words in the phrases will vary in terms of their case, so cases should not be matched during the vba's search and the phrases vary in number of words.
The code below changes misspelt words to the word that corresponds in Sheet10 Column X but only if the word is the only word in the cell.
How can I tailor this code so it finds and corrects words that are part of a phrase in a cell?
It would be an added benefit if any corrected words could be highlighted in bold red so I can easily spot the changes after they've been made (this would be a nice to have but not essential).
Of course please feel free to ask any questions if you need more scoping for this, thanks.
Any help much appreciated.
VBA Code:
Dim LRow As Long, i As Long
Dim varSearch As Variant
With Sheet10
LRow = .Cells(.Rows.Count, 23).End(xlUp).Row '23 relates to Col W
varSearch = .Range("W6:X" & LRow)
End With
With Sheet1.Range("I:I")
For i = LBound(varSearch) To UBound(varSearch)
.Replace what:=varSearch(i, 1), replacement:=varSearch(i, 2), lookat:=xlWhole
Next
End With