Hi Nigel,
Thank you for responding. Following is teh code which iterates cells of 3rd
column starting from 4 to 49. Column 3 contains end dates. When end date is
nearing current date by 2 days or so, it highlights those cells with color.
Code works fine and no errors or warnings. But along with excel sheet it
opens the code also (VBE).
Regards,
Vaibhav
Sub Alerts()
'
' Alerts Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Range("A2").Select
Application.Goto Reference:="Alerts"
Dim msg, cn, td As Integer
Dim dt, k, final_msg As Variant
cn = 4
final_msg = "Following Items are critical :"
Do While cn < 49
k = Worksheets("Sheet1").Cells(cn, 3).Value
If k <> Empty Then
td = DateDiff("d", CDate(k), Now)
If td <= 2 And td > 0 Then
msg = msg + Worksheets("Sheet1").Cells(cn, 2).Value
Worksheets("Sheet1").Cells(cn, 2).Interior.ColorIndex = 15
Worksheets("Sheet1").Cells(cn, 3).Interior.ColorIndex = 15
End If
If td = 0 Then
Worksheets("Sheet1").Cells(cn, 2).Interior.ColorIndex = 33
Worksheets("Sheet1").Cells(cn, 3).Interior.ColorIndex = 33
End If
End If
cn = cn + 1
Loop
final_msg = final_msg + msg
Rem msg = DateDiff("d", "13-JAN-2008", Now)
Rem MsgBox final_msg
Application.Visible = True
End Sub