Please Help: Checkspelling method of range class failed

vaibha

New Member
Joined
Dec 15, 2015
Messages
2
Hello,
I need your help in rectifying the code. This macro goes to certain columns, highlights the errors in magenta, creates a sheet and paste those errors there and also initiates a spellcheck.

But I am receiving an error "Checkspelling method of range class failed".
Here is my code:
Code:
Sub qc_travelator()
Dim wb, gb As Workbook
Dim ws, gs As Worksheet
Dim cb As Workbook
Dim cs As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
Set gb = Workbooks.Add
Set gs = gb.ActiveSheet
col = ws.UsedRange.Columns.Count
Row = ws.UsedRange.Rows.Count
Set cb = ThisWorkbook
Set cs = cb.Sheets("Sheet1")
crow = cs.UsedRange.Rows.Count
tid = ws.Cells(1, 2).Text
strt = 0


    For i = 2 To crow
        If tid = cs.Cells(i, 1).Text Then
        strt = i
        Exit For
        End If
    Next i
    
    If strt = 0 Then
    End
    End If
    
    For i = strt To crow + 1
        If tid <> cs.Cells(i, 1).Text Then
        stp = i - 1
        Exit For
        End If
    Next i
    
    cnt = (stp - strt) + 1
    gin = 1
    For i = strt To stp
    If MsgBox("Spell check in attribute """ & cs.Cells(i, 2).Text & """ ?", vbOKOnly, gin & " of " & cnt) = vbOK Then
            For j = 1 To col
                If ws.Cells(5, j).Text = cs.Cells(i, 2).Text Then
                ws.Activate
                ws.Cells(5, j).Select
                Selection.Interior.Color = vbRed
                Selection.Copy
                gs.Activate
                gs.Cells(1, 1).Select
                Selection.Insert Shift:=xlToRight
                gs.Activate
                gs.Range(gs.Cells(2, 1), gs.Cells(Row, 1)).Select
                Selection.Insert Shift:=xlToRight
                For k = 7 To Row
                        If Application.CheckSpelling(ws.Cells(k, j)) = False Then
                        ws.Activate
                        ws.Cells(k, j).Select
                        Selection.Interior.Color = vbMagenta
                        Selection.Copy
                        gs.Activate
                        gs.Cells(2, 1).Select
                        Selection.Insert Shift:=xlDown
                        ws.Activate
                        Range(ws.Cells(k, j), ws.Cells((k + 1), j)).Select
                        Range(ws.Cells(k, j), ws.Cells((k + 1), j)).CheckSpelling
                        End If
                    Next k
                End If
            Next j
        End If
    gin = gin + 1
    Next i
    
Application.CutCopyMode = False
MsgBox "Done"

End Sub
Please help, as I am not so good with vba.

best regards
VG
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi vaibha,

Which line is returning the error? You have two statements checking the spelling, so it would be easy finding which one is returning the error.

Do you have blank cells within the range? Application.CheckSpelling returns error when the cell is blank.

Does the spelling dialogbox appear during the execution of the macro? Normally, Range.CheckSpelling displays the dialogbox.
 
Upvote 0
Hello Mohammad,
Good Afternoon!

That error is resolved. i forgot to un-protect the sheet.

but now m getting an error.

"Type Mismatch" in the following line.

If Application.CheckSpelling(ws.Cells(k, j)) = False Then


Regards
Vaibha
 
Upvote 0
Hello Vaibha,

First of all, I was mistaken when I said “Application.CheckSpelling returns error when the cell is blank”. This is not true.

Check the value of the cell where the error is returned and see what the type of data is. I did a quick test and found that this error returned if the cell has error value.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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