Data validation using code

G

Gareth

I have the folowing code which works fine when there is data in all the
cells referenced. Unfortunately, column's K and L do not always have data
in them (all cells are date cells).

This causes the validation not to work.

With Range("dob").Validation
..Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween,
Formula1:="=AND(I2>=29221,I2<=TODAY(),I2<=J2,I2<=K2,I2<=L2)”
..ErrorTitle = "Date of birth"
..ErrorMessage = "Entry must be a date between 01/01/1980 and today." &
Chr(10) & _
Chr(10) & "It cannot be greater than either the on, off or died date."
End With

Is there a way around it?

Many thanks.

Gareth
 

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

Top