G
Gareth
Hello all,
I have been using the code below to count the number of data validation
errors on a sheet (datasheet). It has worked sucessfully over a number of
years but all of a sudden when it is run the following message is displayed
and the file closes:
EXCEL.exe has generated errors and will be closed by Windows.
You will need to restart the program.
An error log is being created.
macro:
Sub DVerrors()
Application.ScreenUpdating = False
Sheets("datasheet").Activate
Dim rngDV As Range
Dim cell As Range
Dim countDV As Long
Dim ws As Worksheet
Set ws = ActiveSheet
On Error GoTo errhandler
Set rngDV = ws.Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
countDV = 0
For Each cell In rngDV
If Not cell.Validation.Value Then
countDV = countDV + 1
End If
Next
If countDV = 0 Then
MsgBox "There are no data validation errors on the sheet.",
vbInformation, "Invalid data entries"
ActiveSheet.ClearCircles
ElseIf countDV = 1 Then
MsgBox "There is " & countDV & " data validation error on the sheet.",
vbInformation, "Invalid data entry"
ActiveSheet.CircleInvalid
ElseIf countDV > 1 Then
MsgBox "There are " & countDV & " data validation errors on the sheet.",
vbInformation, "Invalid data entries"
ActiveSheet.CircleInvalid
End If
Exit Sub
errhandler:
MsgBox "There are no data validation errors on the sheet.", vbInformation,
"Invalid data entries"
ActiveSheet.ClearCircles
Application.ScreenUpdating = True
End Sub
Thanks in advance.
Gareth
I have been using the code below to count the number of data validation
errors on a sheet (datasheet). It has worked sucessfully over a number of
years but all of a sudden when it is run the following message is displayed
and the file closes:
EXCEL.exe has generated errors and will be closed by Windows.
You will need to restart the program.
An error log is being created.
macro:
Sub DVerrors()
Application.ScreenUpdating = False
Sheets("datasheet").Activate
Dim rngDV As Range
Dim cell As Range
Dim countDV As Long
Dim ws As Worksheet
Set ws = ActiveSheet
On Error GoTo errhandler
Set rngDV = ws.Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
countDV = 0
For Each cell In rngDV
If Not cell.Validation.Value Then
countDV = countDV + 1
End If
Next
If countDV = 0 Then
MsgBox "There are no data validation errors on the sheet.",
vbInformation, "Invalid data entries"
ActiveSheet.ClearCircles
ElseIf countDV = 1 Then
MsgBox "There is " & countDV & " data validation error on the sheet.",
vbInformation, "Invalid data entry"
ActiveSheet.CircleInvalid
ElseIf countDV > 1 Then
MsgBox "There are " & countDV & " data validation errors on the sheet.",
vbInformation, "Invalid data entries"
ActiveSheet.CircleInvalid
End If
Exit Sub
errhandler:
MsgBox "There are no data validation errors on the sheet.", vbInformation,
"Invalid data entries"
ActiveSheet.ClearCircles
Application.ScreenUpdating = True
End Sub
Thanks in advance.
Gareth