The following bit of VBA will highlight any cells in a sheet with data validation errors:
Sub CheckValidation(sht As Worksheet)
Dim cell As Range
Dim rngDV As Range
Dim dvError As Boolean
On Error Resume Next
Set rngDV = sht.UsedRange.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If rngDV Is Nothing Then
sht.ClearCircles
Else
dvError = False
For Each cell In rngDV
If Not cell.Validation.Value Then
dvError = True
Exit For
End If
Next
If dvError Then
sht.CircleInvalid
sht.Activate
Else
sht.ClearCircles
End If
End If
End Sub
However, the "For Each" loop runs really slowly in sheets with a lot of data validation.
Does anyone know of a way to avoid the "For Each" loop, or speed it up somehow?
I would have thought that the following would be equivalent to set the value of 'dvError':
dvError = Not rngDV.Validation.Value
But for some reason, rngDV.Validation.Value is true even when there are data validation errors.