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

KyleJackMorrison

Board Regular
Joined
Dec 3, 2013
Messages
107
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. 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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top