If you find any post useful then, please do share with others. Thanks!

Popular Posts

Contact

Email me

Need help and that also free? I like to learn this way, in case of any question or for a small task, please feel free to email me with details and example data, if required.

Friday, January 27, 2023

Spell Check VBA Code/Macro

 We can use below code to run against long list of rows having text, to highlight misspelled words in red. Just select the rows and run this code.


Sub Spell()


Dim cel As Range, CellLen As Long, CurChr As Long, TheString As String


For Each cel In Selection

    For CurChr = 1 To Len(cel.Value)

        If Asc(Mid(cel.Value, CurChr, 1)) = 32 Then

            If InStr(CurChr + 1, cel.Value, " ") = 0 Then

                TheString = Mid(cel.Value, CurChr + 1, Len(cel.Value) - CurChr)

            Else

                TheString = Mid(cel.Value, CurChr + 1, InStr(CurChr + 1, cel.Value, " ") - CurChr)

            End If

            If Not Application.CheckSpelling(Word:=TheString) Then

                cel.Characters(CurChr + 1, Len(TheString)).Font.Color = RGB(255, 0, 0)

            Else

                cel.Characters(CurChr + 1, Len(TheString)).Font.Color = RGB(0, 0, 0)

            End If

            TheString = ""

        End If

    Next CurChr

Next cel


End Sub

No comments:

Post a Comment