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:
Please help, as I am not so good with vba.
best regards
VG
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
best regards
VG
Last edited by a moderator: