vba to correct spelling mistakes of pre-determined words using wildcards

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm looking for some vba that will do the following:

I have cells in Sheet2 from cell I101 down (the last cell is variable) that contain text as phrases.

I have a table in Sheet1 W6:X###. In column W each cell has a letter/wildcard combination (eg. c*m*c*n). Next to each of these in adjacent cells there are words in column X (eg. communication). The table will vary in number of rows down as it grows.

I'm looking for some vba that will look at all the phrases in Sheet2 I101:I### and where it finds a word in the phrase that meets a letter/wildcard combination (from Sheet1 W6:W##) it changes it to the word that corresponds in Sheet1 Column X. The words in the phrases will vary in terms of their case, so cases should not be matched during the vba's search.

So, if Sheet2 cell I111 contains the phrase 'Please send comuniccation now' the vba will replace the wrongly spelled 'comuniccation' with the correct 'communication' spelling and highlight the changed word bold red.

Notes:
- Ignore the column headers in the examples shown they will not be present.
- I need the letter/wildcard combinations to look for single words only and not spread across several words
- the table in Sheet2 shows the finished output although I noticed in the preview of the post that the changed words were not highlighted red?!

I am aware that this method has limitations and could change a word that meets the criteria but isn't meant to be 'communication' so I will have to set up the letter/wildcard combinations carefully. It won't be 100% but it will be pretty close and I'm targeting commonly misspelled words in the context of the project. The red highlighting will assist me checking the output. If anyone has any ideas re. the advanced use of wildcards etc. then I'm all ears!

Any help much appreciated.

Book1.2.xlsx
VWXY
4
5LookupCorrection
6c*m*c*ncommunication
7m*g*rmanager
8m*g*ntmanagement
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Sheet1


Book1.2.xlsx
HIJ
99
100phrase
101the person walks down the road
102The hotel management are all away on holiday
103why is the restaurant closed?
104it's the best place around here
105what do you mean??
106"It's not funny anymore!"
107sixty five benches
108I am the new manager here
109the bus is late
110the car is so slow
111please send communication now
112the cat and the dog got hit by a train
113great parking here
114
115
116
117
118
119
120
121
Sheet2
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Wondered if anyone had any ideas on this one?
Thanks in advance.
 
Upvote 0
I have the code below but it only works changing a word that exists on it's own in the cell.
Does anyone know how I can adapt it so it will find the word in a text string in a cell and make the change?
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
 
Upvote 0
I guess I'd better try another forum for this one.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,111
Members
453,021
Latest member
Justyna P

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