Notify if the date expires in Excel DB

eXtremer

Board Regular
Joined
Oct 20, 2010
Messages
74
Hi all.

There is a excel database with columns, there is a column with dates and I need to be notified by excel somehow that it past for example 30 days from that date, is it possible to implement such a thing in excel ? I need to be notified just once, after that to click on it and the reminder has to be set OFF.

I really need to find a workaround.

Thank you in advance.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What date I should take into account? Where it's located?
 
Upvote 0
And is there a spare column we can use to store a flag to indicate that the notification has been issued?
 
Upvote 0
Ruddles, to store a flag invisible Name can be used.
 
Upvote 0
This is an example of how the DB looks like...
Can't see it - file sharing sites are blocked by the company firewall.

You could do something like this. Paste this code in the worksheet code module in a copy of your workbook:-
Code:
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]Const KEY_COL As Integer = [COLOR=red][B]1
[/B][/COLOR]Const DATE_COL As Integer = [COLOR=red][B]13
[/B][/COLOR]Const NOTIFIED_COL As Integer = [COLOR=red][B]14[/B][/COLOR][/FONT]
[FONT=Courier New]Const ALERT_PERIOD As Integer = 30
[/FONT]
[FONT=Courier New][COLOR=green]' use this event handler as it's called every time someone moves around the worksheet[/COLOR][/FONT]
[FONT=Courier New][COLOR=#008000][/COLOR][/FONT] 
[FONT=Courier New]Private Sub Worksheet_Calculate()[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]  Dim iLast As Long
  Dim iRow As Long
  Dim ws As Worksheet
  Set ws = ActiveSheet
  
  iLast = ws.Cells(ws.Rows.Count, DATE_COL).End(xlUp).Row
  For iRow = 2 To iLast
    If Not IsEmpty(ws.Cells(iRow, DATE_COL)) And IsEmpty(ws.Cells(iRow, NOTIFIED_COL)) Then
      If ws.Cells(iRow, DATE_COL) < Now() + ALERT_PERIOD Then
        [COLOR=green]' if the date cell isn't empty and it's within the next 30 dayts and we haven't already
        ' notified the user, then display a message box and set the notification date
[/COLOR]        MsgBox "Date for " & ws.Cells(iRow, KEY_COL) & " expires on " _
             & Format(ws.Cells(iRow, DATE_COL), "dd/mm/yyyy")
        ws.Cells(iRow, NOTIFIED_COL) = Format(Now(), "dd/mm/yyyy")
      End If
    End If
  Next iRow
  
End Sub[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]  Dim oCell As Range
  Dim ws As Worksheet
  Set ws = ActiveSheet
  
  If Not Intersect(Target, ws.Columns(DATE_COL)) Is Nothing Then
    For Each oCell In Intersect(Target, ws.Columns(DATE_COL))
      [COLOR=green]' if the user changes the expiry date, reset the notifcation flag
[/COLOR]      oCell.Offset(0, 1).ClearContents
    Next oCell
  End If
  
End Sub[/FONT]

Set DATE_COL to point to the column which holds the expiry date, NOTIFIED_COL to point to a spare column where we'll store the date when the warning message was displayed and KEY_COL to point to whichever column holds the identifying information for that entry. I've set them to M (as you said), N (you have to set this to a spare column) and A (which might hold the person's name, for example).

Whenever the worksheet is recalculated*, the date column is checked and if it's in the next ALERT_PERIOD days and the notification column is blank, you get a warning and the notification date is set. Whenever the expiry date is changed, the notification flag is reset to blank.

* This assumes that your worksheet has formulae in it which trigger the Worksheet_Calculate event.

See how you go with that.
 
Upvote 0
Can't see it - file sharing sites are blocked by the company firewall.

You could do something like this. Paste this code in the worksheet code module in a copy of your workbook:-
Code:
[FONT=Courier New]Option Explicit[/FONT]
 
[FONT=Courier New]Const KEY_COL As Integer = [COLOR=red][B]1
[/B][/COLOR]Const DATE_COL As Integer = [COLOR=red][B]13
[/B][/COLOR]Const NOTIFIED_COL As Integer = [COLOR=red][B]14[/B][/COLOR][/FONT]
[FONT=Courier New]Const ALERT_PERIOD As Integer = 30
[/FONT]
[FONT=Courier New][COLOR=green]' use this event handler as it's called every time someone moves around the worksheet[/COLOR][/FONT]
 
[FONT=Courier New]Private Sub Worksheet_Calculate()[/FONT]
 
[FONT=Courier New]  Dim iLast As Long
  Dim iRow As Long
  Dim ws As Worksheet
  Set ws = ActiveSheet
  
  iLast = ws.Cells(ws.Rows.Count, DATE_COL).End(xlUp).Row
  For iRow = 2 To iLast
    If Not IsEmpty(ws.Cells(iRow, DATE_COL)) And IsEmpty(ws.Cells(iRow, NOTIFIED_COL)) Then
      If ws.Cells(iRow, DATE_COL) < Now() + ALERT_PERIOD Then
        [COLOR=green]' if the date cell isn't empty and it's within the next 30 dayts and we haven't already
        ' notified the user, then display a message box and set the notification date
[/COLOR]        MsgBox "Date for " & ws.Cells(iRow, KEY_COL) & " expires on " _
             & Format(ws.Cells(iRow, DATE_COL), "dd/mm/yyyy")
        ws.Cells(iRow, NOTIFIED_COL) = Format(Now(), "dd/mm/yyyy")
      End If
    End If
  Next iRow
  
End Sub[/FONT]
 
[FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)[/FONT]
 
[FONT=Courier New]  Dim oCell As Range
  Dim ws As Worksheet
  Set ws = ActiveSheet
  
  If Not Intersect(Target, ws.Columns(DATE_COL)) Is Nothing Then
    For Each oCell In Intersect(Target, ws.Columns(DATE_COL))
      [COLOR=green]' if the user changes the expiry date, reset the notifcation flag
[/COLOR]      oCell.Offset(0, 1).ClearContents
    Next oCell
  End If
  
End Sub[/FONT]
Set DATE_COL to point to the column which holds the expiry date, NOTIFIED_COL to point to a spare column where we'll store the date when the warning message was displayed and KEY_COL to point to whichever column holds the identifying information for that entry. I've set them to M (as you said), N (you have to set this to a spare column) and A (which might hold the person's name, for example).

Whenever the worksheet is recalculated*, the date column is checked and if it's in the next ALERT_PERIOD days and the notification column is blank, you get a warning and the notification date is set. Whenever the expiry date is changed, the notification flag is reset to blank.

* This assumes that your worksheet has formulae in it which trigger the Worksheet_Calculate event.

See how you go with that.

Thank you very much Ruddles, I will test this code and get back to you later.

Regards
 
Upvote 0
Ok, so in the column 13 is the registration date, I need to be notified 30 days after the registration date.
I inserted column 14 (named Expiry date) and column 15 (Notification)

DATE_COL = 14
NOTIFIED_COL = 15
KEY_COL = 2 (INSURACNE POLICY)
Example:

column 13: 15.06.2011
column 14: 16.06.2011
column 15: BLANK

What should happen in this case ? So I would know the code is working, something should blink or else tomorrow in the column 15 ?
 
Upvote 0
Thank you very much Ruddles, I will test this code and get back to you later.
Okay, thanks for the response. And I'll take a look at your worksheet when I get home, as I'll be able to access the file-sharing site from there.

In the meantime, consider this: the code has to be run periodically in order to detect when the expiry dates become 'alertable'. That could be:-
  • only once, when the workbook is opened (or just before it's closed)
  • every time the workbook is saved
  • every time someone manually modifies the contents of a cell - any cell (if this happens during normal use - which isn't always the case)
  • every time the worksheet recalculates (which it won't unless there are formulae in it)
  • every X seconds or minutes (using the .OnTime method - which I try to avoid)
You have to decide which of these 'triggers' is the one you want. If you have a lot of data and you do it every time you enter a value, for example, that will slow down the response of the worksheet.
 
Upvote 0
Code:
[B]DATE_COL = [COLOR=red]14[/COLOR][/B]
[B]NOTIFIED_COL = [COLOR=blue]15[/COLOR][/B]
[B]KEY_COL = 2[/B]
Yes, that's good, but in the worksheet you just need to put the expiry date in N. Leave O blank - that's where my code will put a flag indicating that the alert has been raised so it isn't raised again every time the code runs.

Sorry though, there's one change. Instead of:-
Code:
Private Sub Worksheet_Calculate()
put:-
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

That will trigger the alert code every time you move around the sheet. It's not ideal but it's good enough to get the system working for the moment. When it's working, we'll decide how we're going to trigger it (see my previous post).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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