I tried to put up a code so that when a reagent expires in 7 days, a message alert pops up, and when the workbook opens, the reagent is expired. The out-of-date reagent needs to be mentioned in the message. I tried to make the code work only for the "FA Reagents" (A4:A20) and the expiration dates for those reagents (C4:C20), but I finally want the code to work for every reagent on this page.
Excel Sheet
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim rReagents As Range
Set rReagents = Range("A4:A20")
Dim rExpiration As Range
Set rExpiration = Range("C4:C20")
Dim lLastrow As Long, i As Long
Set ws = Worksheets("Reagent-Equipment")
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 ("Reagent expiring in 7 days for " & .Cells(i, 1))
If .Cells(i, 2) = Date Then MsgBox ("Reagent expiring today for " & .Cells(i, 1))
Next
End With
End Sub
This is the code I tried, but I can't notification to pop up when the workbook opens when a reagent is expired or expired within 7 days.