Jonathan Harrison
New Member
- Joined
- Jul 15, 2011
- Messages
- 43
I have a fairly simple macro to check the number of misspelled words in a range and output the number of errors to another range. The script works fine, but it takes about 1 second per cell, which becomes a problem when I want to run it on 30,000 records. Is there a more efficient way to do this?
Thanks!
Count the number of errors in a cell:
Loop from user defined range to check multiple cells and output to a user defined range:
Thanks!
Count the number of errors in a cell:
Code:
Public Function countmisspells(cellToCheck As Range) As Long
'Define Excel app so I can access the spell check function of Excel
Dim xlApp As New Excel.Application
'errorCount
Dim errorCount As Long
'slit each word in the cell up
wordHolder = Split(cellToCheck.Value, " ")
'for each word in the array, check the spelling
For Each singleWord In wordHolder
'if the word is not spelled correctly
If Not xlApp.CheckSpelling(singleWord) Then
'increase total misspell count
errorCount = errorCount + 1
End If
Next
'return the number of misspells as the result of the function
countmisspells = errorCount
Set xlApp = Nothing
End Function
Loop from user defined range to check multiple cells and output to a user defined range:
Code:
For i = 1 To inputCells.Rows.Count
For j = 1 To inputCells.Columns.Count
outputCells.Cells(i, j).Value = countmisspells(inputCells.Cells(i, j))
outputCells.Cells(i, j).ClearFormats
'MsgBox spellErrors
Next j
Next i