VBA pop-up reminder for date column

user294390

New Member
Joined
Feb 17, 2021
Messages
7
Office Version
  1. 2019
Hi,

I am compiling a database and require pop-up alerts for one date column. My spreadsheet is like this:
Column A - vendor name
Column B - expiry date of subscription
and several columns beyond, with other details like address, products etc.

I am trying to add a message box alert 7 days before the date as well as on that date, showing "Subscriptions expiring in 7 days for <corresponding vendor names in column A>"
or "Subscriptions expiring today for <corresponding vendor names in column A>" according to the date.
Would appreciate any help with this, thank you!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Put this macro in ThisWorkbook:

VBA Code:
Private Sub Workbook_Open()
    Dim ws As Worksheet
    Dim rVendor As Range
    Dim rEdate As Range
    Dim lLastrow As Long, i As Long
    Set ws = Worksheets("Sheet1") 'name of sheet with data
    lLastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
    With ws
        For i = 2 To lLastrow
            If .Cells(i, 2) = Date + 7 Then MsgBox ("Subscriptions expiring in 7 days for " & .Cells(i, 1))
            If .Cells(i, 2) = Date Then MsgBox ("Subscriptions expiring today for " & .Cells(i, 1))
        Next
    End With
End Sub
 
Upvote 0
Solution
Put this macro in ThisWorkbook:

VBA Code:
Private Sub Workbook_Open()
    Dim ws As Worksheet
    Dim rVendor As Range
    Dim rEdate As Range
    Dim lLastrow As Long, i As Long
    Set ws = Worksheets("Sheet1") 'name of sheet with data
    lLastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
    With ws
        For i = 2 To lLastrow
            If .Cells(i, 2) = Date + 7 Then MsgBox ("Subscriptions expiring in 7 days for " & .Cells(i, 1))
            If .Cells(i, 2) = Date Then MsgBox ("Subscriptions expiring today for " & .Cells(i, 1))
        Next
    End With
End Sub
Thank you so much! It works perfectly.
 
Upvote 0
Hi, how to I get the code to run automatically every time I open the sheet? Sometimes it works but otherwise I have to manually run the code to view the pop-ups
 
Upvote 0
The code would be expected to run whenever the workbook is opened UNLESS macros or events are disabled
The problem may originate outside this workbook
Is another workbook open at the time when the popup fails to appear?
 
Upvote 0
The code would be expected to run whenever the workbook is opened UNLESS macros or events are disabled
The problem may originate outside this workbook
Is another workbook open at the time when the popup fails to appear?
Initially macros were disabled with notification, I changed it to enable all macros (very reluctantly, since I usually download a lot of files from the internet) but it didn't work every time. No other workbook was open
What are events?
 
Upvote 0
The macro iteself is an event macro because it is triggered when an "event" occurs - the event being opening the workbook.
We could change the trigger so that the macro runs when you activate the sheet rather than opening the workbook
Let me know if you would prefer that and I will explain the steps you need to take
 
Upvote 0
Sure, either way is fine for me but since the workbook trigger isn't working we can try it when the sheet is activated instead (y)
 
Upvote 0
I have amended the macro to group messages together if more than one row throws an alert


1. Delete Wokbook_Open procedure

2. Place code below in the SHEET code window for sheet1
(right click on sheet name tab \ view code \paste it into the open window)
VBA Code:
Private Sub Worksheet_Activate()
    Dim rVendor As Range, rEdate As Range, Msg1 As String, Msg2 As String
    Dim lLastrow As Long, i As Long
    Const m1 = "Subscriptions expiring in 7 days for "
    Const m2 = "Subscriptions expiring today for "
  
    lLastrow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lLastrow
        If Cells(i, 2) = Date + 7 Then Msg1 = Msg1 & vbCr & Cells(i, 1)
        If Cells(i, 2) = Date Then Msg2 = Msg2 & vbCr & Cells(i, 1)
    Next
    If Len(Msg1) > 0 Then MsgBox m1 & vbCr & Msg1, , ""
    If Len(Msg2) > 0 Then MsgBox m2 & vbCr & Msg2, , ""
End Sub

Does your workbook contain another sheet?
- if it doesn't ... insert another sheet and name it "Landing"

Activate a different sheet and then click on sheet1 to trigger the macro

We will add a bit more code after you have got the above working so that it runs when the workbook is opened without using Workbook_Open
 
Upvote 0
I have amended the macro to group messages together if more than one row throws an alert


1. Delete Wokbook_Open procedure

2. Place code below in the SHEET code window for sheet1
(right click on sheet name tab \ view code \paste it into the open window)
VBA Code:
Private Sub Worksheet_Activate()
    Dim rVendor As Range, rEdate As Range, Msg1 As String, Msg2 As String
    Dim lLastrow As Long, i As Long
    Const m1 = "Subscriptions expiring in 7 days for "
    Const m2 = "Subscriptions expiring today for "
 
    lLastrow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lLastrow
        If Cells(i, 2) = Date + 7 Then Msg1 = Msg1 & vbCr & Cells(i, 1)
        If Cells(i, 2) = Date Then Msg2 = Msg2 & vbCr & Cells(i, 1)
    Next
    If Len(Msg1) > 0 Then MsgBox m1 & vbCr & Msg1, , ""
    If Len(Msg2) > 0 Then MsgBox m2 & vbCr & Msg2, , ""
End Sub

Does your workbook contain another sheet?
- if it doesn't ... insert another sheet and name it "Landing"

Activate a different sheet and then click on sheet1 to trigger the macro

We will add a bit more code after you have got the above working so that it runs when the workbook is opened without using Workbook_Open
Done, as you said it works when I switch from Landing to Sheet 1
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,531
Members
449,169
Latest member
mm424

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