Hi
Try this.
Sub CheckDate()
Dim a, select1, from1, where1 As String
Worksheets("Temporary").Activate
Range("A3:IV65000").ClearContents
select1 = "SELECT " & Worksheets("Generate Report").Range("B4") & " "
from1 = "FROM " & Worksheets("Generate Report").Range("C4") & " "
where1 = "WHERE " & Worksheets("Generate Report").Range("D4") & " "
a = select1 & from1 & where1 & orderedBy
Worksheets("Temporary").Activate
Cells(2, 1).Select
GetData (a)
i = 3
'Do While (Cells(i, 1).Value <> "")
For i = 3 To Cells(Rows.Count, 1).End(xlUp).Row
If Len(Cells(i, 9)) = 0 And Len(Cells(i, 10)) = 0 Then
Cells(i, 13).ClearContents
Else
docol = 9
If Len(Cells(i, 9)) = 0 Then docol = 10
difference = (DateDiff("d", Int(Cells(i, docol)), Int(Now())))
' difference2 = (DateDiff("d", Int(Cells(i, 10)), Int(Now())))
If difference >= 30 And difference < 40 Then
Cells(i, 13).Interior.Color = vbYellow
Cells(i, 13).Font.Color = vbBlack
Cells(i, 13) = "30 days warning"
End If
If difference >= 40 And difference < 45 Then
Cells(i, 13).Interior.ColorIndex = 45
Cells(i, 13).Font.Color = vbBlack
Cells(i, 13) = "40 days warning"
End If
If difference > 45 Then
Cells(i, 13).Interior.Color = vbRed
Cells(i, 13).Font.Color = vbWhite
Cells(i, 13) = "45 days warning"
End If
If difference < 30 Or Cells(i, 9) = "" Then
Cells(i, 13).Interior.Color = vbWhite
End If
End If
'i = i + 1
'Loop
Next i
End Sub
If that doesn't really do what you are chasing, then add an example file. I'm not sure about the last test you have that you want to really clear out column 13 if column 9 is blank...
rylo
Bookmarks