Hi Geo
The below macro displays a notification message with the total dates
expired/close to expiry and activate the sheet; and also highlights the cells
for easy identification. You can either call this from sheet Activate event
or even run as a separate macro whenever you need. Try and feedback
Private Sub Worksheet_Activate()
Call ExpiryNotification
End Sub
Sub ExpiryNotification()
Dim ws As Worksheet, rngTemp As Range
Dim lngRow As Long, lngExp As Long, lngWarn As Long
'Adjust the sheet name to suit
Set ws = Worksheets("Sheet1")
Set rngTemp = ws.Range("rngDate")
'Adjust the date column to suit. For this example it is A
'Assume you have header in row 1; and date starts from row 2
For lngRow = 2 To ws.Cells(Rows.Count, rngTemp.Column).End(xlUp).Row
If ws.Cells(lngRow, rngTemp.Column) > 0 Then
ws.Cells(lngRow, rngTemp.Column).Interior.ColorIndex = 0
If ws.Cells(lngRow, rngTemp.Column) <= Date Then
ws.Cells(lngRow, rngTemp.Column).Interior.ColorIndex = 3
lngExp = lngExp + 1
ElseIf ws.Cells(lngRow, rngTemp.Column) < Date + 5 Then
ws.Cells(lngRow, rngTemp.Column).Interior.ColorIndex = 6
lngWarn = lngWarn + 1
End If
End If
Next
If lngWarn + lngExp > 0 Then MsgBox "Dates expired : " & _
lngExp & vbCrLf & "Due to expire : " & lngWarn, _
vbInformation, ws.Name: ws.Activate
End Sub