View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
MJKelly MJKelly is offline
external usenet poster
 
Posts: 114
Default multiple validation


Hi,
The code below checks a range for errors. I want to build on the line
which checks the value for "AL" or "SL" to check for some 30 different
possibilities. Is there a better way of doing this than Xor c.value =
"Pm" Xor c.value = "XD" etc. Like I say this will be around 30
different possibilities.

I tried
if c.value < ("AL", "SL", "PM") then
do something
end if

but this doesnt work. Is there a syntax I can use other than a long
winded Xor?

Sub Validate_Status()
'checks for errors in status names entries

Dim ErrCount
Dim c As Range

ThisWorkbook.Sheets("Sheet1").Select
Range("A1:A10").ClearFormats

For Each c In Range("A1:A10")
If Not c.Value = "" Then 'the cell is not empty
If Not IsNumeric(c.Value) Then 'the cell value is not numeric
'validate the staus codes
If Not c.Value = "AL" Xor c.Value = "SL" Then
c.Interior.ColorIndex = 3
ErrCount = ErrCount + 1
End If
End If
End If
Next c

MsgBox ErrCount

End Sub

Kind regards,
Matt