Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VBA to spellcheck characters 3 to 10 in a column

0

Hello. I've been trying for ages to spellcheck a column, but only characters 3 to 10. All words have exactly 10 characters. Wrongly spelled words have their font/fill colours inverted. Either highlighting the whole word or characters 3:10 is okay.

I have modified the following code from AI several time, without success. It seems initially that Excel will not accept characters 3:10, only 3, 10. I have no doubt there will be other dubious coding, but I haven't managed to get further into the coding to test it.

Thank you so much for any help you can offer. 

Sub Spell_long()

    Dim myrange As Range
     substring = myrange(3:10)
     Selection.SpecialCells(xlVisible).Visible
     For Each myrange In Selection
     If Application.CheckSpelling(word:=myrange.Value) = False Then
     myrange.Font.Color = vbWhite
     myrange.Interior = vbBlack
    End If
    Next 
End Sub
Answer
Discuss

Discussion

@MrEMann

Thank you for selecting my answer. Glad I was able to help.

Cheers   :-)
WillieD24 (rep: 707) Sep 17, '25 at 9:57 am
Add to Discussion

Answers

0
Selected Answer

Hello again MrEMann,

Personally I don't put a lot of faith in AI results, but that's just me.

Application.CheckSpelling checks the spelling of a complete word, it cannot check the spelling of the last 8 of 10 characters as you have suggested. Are the first 2 characters numbers and the characters 3 thru 10 spell a word?

Your code has a few errors (but you know that): 1) you have not declared the type of variable "substring" is; 2) myrange(3:10) should be myrange("3:10") but that tells VBA that "substring" is columns 3 thru 10. 

Are you wanting to spellcheck just one column?

Assuming what you want to check is ##xxxxxxxx ( 2 numbers followed by an 8 letter word - 10 characters). Assuming you want to check these entries in a particular column.

I have created some code to do this. (see attached file).

Sub Check_2()

' macro written by WillieD24 for teachexcel.com  Sept/2025

' declare variables
Dim LR As Long   ' last used row of column
Dim RowNum As Long   ' row number of cell being checked
Dim ColNum As Long   ' number of column being checked
Dim ChkWrd As String   ' the word being checked for spelling
Dim WordCnt As Long   ' count of words mis-spelled

RowNum = 6   ' first row to be checked
ColNum = 3   ' column to be checked

LR = Cells(Rows.Count, ColNum).End(xlUp).Row
'MsgBox LR

Do Until RowNum > LR
    Cells(RowNum, ColNum).Select
    ChkWrd = Right(Cells(RowNum, ColNum), 8)
    'MsgBox ChkWrd
    If Application.CheckSpelling(ChkWrd) = False Then
        With Selection
            ' MsgBox Application.CheckSpelling(Right(Cells(RowNum, ColNum), 8))
            .Font.Color = vbWhite
            .Interior.Color = vbBlack
            WordCnt = WordCnt + 1
        End With
    End If
    RowNum = RowNum + 1
Loop
Range("B2").Select
MsgBox WordCnt & "  are words mis-spelled"

End Sub
'
Column "C", beginning withrow 6, has 15 random 8 character words with a 2-digit prefix. The code checks the spelling in all used cells.

If this solves things for you please mark my answer as Selected.

Cheers   :-)

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login