Updating existing VBA code to highlight cells

hnt007

Board Regular
Joined
Dec 18, 2021
Messages
98
Office Version
  1. 365
Platform
  1. MacOS
Hello there! Thank you very much for helping me with this code. So I have this code to highlight words that are misspelled in red, but I would love to also have the cells that contain misspelled words turned "White, Background 1, 15% Darker" (see attached image).

Public Sub ThisOne()
Set MySheet = ActiveSheet

For Each MyCell In MySheet.Range("D8:D1000")
If MyCell.Value <> MyCell.Formula Then GoTo NextCell:
If Application.CheckSpelling(MyCell.Value) Then GoTo NextCell:

MySentence = " " & MyCell.Value
i = 2
While i < Len(MySentence)
If Mid(MySentence, i - 1, 1) = " " And Mid(MySentence, i, 1) <> "" Then
j = InStr(i, MySentence, " ") - 1
If j = -1 Then j = Len(MySentence)
MyWord = Mid(MySentence, i, j - i + 1)
If Not Application.CheckSpelling(MyWord) Then
With MyCell.Characters(Start:=i - 1, Length:=j - i + 1).Font
.Underline = xlUnderlineStyleNone
.Color = RGB(255, 0, 0)
End With
End If
i = j + 1
End If
i = i + 1
Wend

NextCell:
Next MyCell

End Sub
 

Attachments

  • Screen Shot 2022-05-05 at 4.26.12 PM.png
    Screen Shot 2022-05-05 at 4.26.12 PM.png
    51.7 KB · Views: 10
Last edited by a moderator:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Are you trying to add font.color, not interior.color, aren't you?
replace "interior" with "font"
 
Upvote 0
Are you trying to add font.color, not interior.color, aren't you?
replace "interior" with "font"
Thanks for your help! Well I already have the code working to turn the font red when something is misspelled, I'm now trying to highlight the cell that countain that red font in gray. So if a word is misspelled, I'd have a gray cell with a red word in it
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,222
Members
449,091
Latest member
jeremy_bp001

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