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: 11
Last edited by a moderator:
I found a solution, I'm adding a 2nd module with

VBA Code:
Sub HighlightMissspelledCells()
    Dim rng As Range
    For Each rng In ActiveSheet.Range("D8:D1000")
        If Not Application.CheckSpelling(rng.Text) Then
            rng.Interior.ColorIndex = 15
        End If
    Next rng
End Sub

And I'm creating another code to run both macros at the same time. Thanks for all your help!
 
Last edited by a moderator:
Upvote 0
Solution

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
@hnt007 by the way, you know that ColorIIndex = 15 is not giving you "White, Background 1, 15% Darker" right ?
It is slightly darker and is RGB(192,192,192). It is very close but not exactly = "White, Background 1, 25% Darker" which is RGB(191,191,191)
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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