Expiry date: Date in cell has expired over 3 years then...

KyleJackMorrison

Board Regular
Joined
Dec 3, 2013
Messages
96
Office Version
2019
Platform
Windows
Hello,

I have a code that displays a msgbox when it reaches the date +1.
What I'm trying to do is get the code to display the message box if the date in column H9:H100 is over Now()+30 (Today + 30 days) and to continue displaying the expiry message (even after +30 days) until the date has changed.

Here is the code i have so far:

Code:
Sub ExpiryDateA()
Dim rowNumber As Long
Dim thisSheet As Worksheet
Dim cellToCheck As Range
Dim ANum As String, ATitle As String, AName As String, ACourse As String
Dim ADate As String
Dim AResponse As Integer
Set thisSheet = ActiveSheet 'Makes the sheet active
For rowNumber = 9 To thisSheet.Cells(Rows.Count, 8).End(xlUp).Row 
Set cellToCheck = thisSheet.Cells(rowNumber, 8) 'cells to check 'S'
     
     If cellToCheck.Value = DateAdd("d", 1, Date) Then 
        ANum = Sheets("1 Course Sheet").Range("D" & rowNumber).Value 
        ATitle= Sheets("1 Course Sheet").Range("E" & rowNumber).Value
        AName = Sheets("1 Course Sheet").Range("F" & rowNumber).Value
        ACourse= Sheets("1 Course Sheet").Range("H7").Value
        ADate = Sheets("1 Course Sheet").Range("H" & rowNumber).Value
     
        AResponse = MsgBox("" & ATitle & " " & AName & "'s " & ACourse & " has expired on: " & Format(ADate, "dddd dd mmmm yyyy") & "." & _
        vbNewLine & vbNewLine & "Please book " & ATitle & " " & AName & " this course again.", vbCritical, "Due date course") 'Message Box
    
    End If
NextLine:
Next rowNumber
End Sub
As you can see the code only finds dates with today's date +1.
I have tried something like:
Code:
If cellToCheck.Value < DateAdd("d", 30, Date) Then
But that seems to display the message box for everything including blank cells. (which results in me frantically spamming ESC).

Any help is appreciated.

KJM
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Watch MrExcel Video

Forum statistics

Threads
1,100,209
Messages
5,473,184
Members
406,849
Latest member
gustavor0

This Week's Hot Topics

Top