Determining invalid cells (data validation, vba)

  • Thread starter Thread starter Nigel
  • Start date Start date
N

Nigel

I have a series of cells with validation defined using the
data->validation option.

Some of the cells can be invalid to start with.

I can use the audit tool bar to circle the cells which are
invalid.

How can I determine which cells are invalid using VBA?

Thanks

Nigel
 
You can check the validation property:

'=======================
Sub ColourValidationCells()
'If validation value for the cell is false,
'colour the cell red
Dim rng As Range
Dim c As Range

On Error GoTo errhandler
Set rng = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

For Each c In rng
If Not c.Validation.Value Then
c.Interior.ColorIndex = 3
Else
c.Interior.ColorIndex = xlNone
End If

Next
Exit Sub

errhandler:
MsgBox "No cells with data validation"

End Sub
'===============================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top