1

I created a simple code to highlight spelling errors in certain columns, but it causes excel to stop responding every time I run it. While the code itself works fine, it is a hindrance to have to wait for two minutes before it starts running again.

Is there any way I could fix this?

Option Explicit

Sub Check_Cell()
    Dim wd As Range
    Dim chkCell As Range
    
    Set chkCell = ActiveSheet.Range("F:H:I:J")
    For Each wd In chkCell
    If Not Application.CheckSpelling(word:=wd.Text) Then
        wd.Interior.Color = vbGreen
        
    End If
Next wd


End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • 1
    That's a lot of cells to loop over. Maybe [find the last cell](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) instead of looping over every single cell in those columns. – BigBen Nov 17 '20 at 18:06
  • 1
    With `ActiveSheet.Range("F:H:I:J")` are you trying to exclude column `G`? If so, that construct won't do that. – chris neilsen Nov 17 '20 at 18:23

1 Answers1

0

This may help. Replace:

 Set chkCell = ActiveSheet.Range("F:H:I:J")

with:

 Set chkCell = Intersect(ActiveSheet.Range("F:H:I:J"),ActiveSheet.Usedrange)
Gary's Student
  • 95,722
  • 10
  • 59
  • 99