Hi All,
I'm having an issue with a conditional formating reference. Here is my current code:
Sub Test()
For intIndex = 2 To intLR ' exclude header
If Range("D" & intIndex) <= Range("J1") Then ' If date in column D is <= date in J1
Range("A" & intIndex & ":E" & intIndex).Interior.ColorIndex = 3 ' Change fill to red
' The next line checks if date in column C is >= date in G1 and text in column B is indented-
ElseIf Range("C" & intIndex) >= Range("G1") And Range("B" & intIndex).IndentLevel > 1 Then
Range("A" & intIndex & ":E" & intIndex).Interior.ColorIndex = 20 ' Change fill to Blue
ElseIf Range("C" & intIndex) >= Range("G1") Then ' If date in column C is >= date in G1
Range("A" & intIndex & ":E" & intIndex).Interior.ColorIndex = 4 ' Change fill to Green
ElseIf Range("C" & intIndex) < Range("G1") Then ' If date in column C is < date in G1
Range("A" & intIndex & ":E" & intIndex).Interior.ColorIndex = 0 ' No fill
End If
Next intIndex
Exit Sub
The dates in G1 and J1 are user defined, but any dates in columns C or D are static. Everything works fine so far unless the user enters a date in G1 that is less than any date in Column C, which goofs up all the formatting.
My question is, would there be any way to check if the date in G1 is less than any date in column C, then perform an event if true?
Something like:
If Range("G1") < Range("C" & intIndex) Then ' If date in G1 < any date in column C
msgbox "You entered the wrong date"
Exit Sub
End If
(which doesnt work).
Any help would be greatly appreciated, thanks!
Bookmarks