What is wrong with my code?
Hi All,
I am trying to write a vb code to validate date fields in a particular column which I call from a menu. However, I keep having error with the if statement. I have not been able figure out what is wrong. Here, is the code.
[vba] Function DateFormatChecking(columnname As Integer)
Dim rowcount
Dim R
rowcount = Range("A65536").End(xlUp).Row
For R = 1 To rowcount
strVal = Sheet1.Cells(R, columnname).Value
If (((strVal <> "") And (strVal.NumberFormat <> "mm/dd/yy")) Or ((strVal <> "") And _
(strVal.NumberFormat <> "mm/dd/yyyy"))) Then
Sheet1.Cells(R, columnname).Interior.ColorIndex = 7
End If
Next
End Function[/vba]
Thanks
Lucpian
EDIT: Added Code Tags Tommy