I think BeforeClose event will best suit this scenario.
Assuming Col. A is Name, B is Date1 and C is Date2, then
Place the following code on ThisWorkbook Module.....
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Dim lr As Long, cnt As Long
Dim rng As Range, cell As Range
Set ws = Sheets("Sheet1")
lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & lr)
For Each cell In rng
If cell.Offset(0, 1) = "" And cell + 21 < Date Then
cell.Offset(0, 1).Interior.ColorIndex = 3
cnt = cnt + 1
Else
cell.Offset(0, 1).Interior.ColorIndex = xlNone
End If
Next cell
If cnt > 0 Then
MsgBox "Please fill the cells highlighted with Red color.", vbCritical
Cancel = True
End If
End Sub
So once user tries to close the workbook, the code will highlight the col. C if it is not filled as per the criteria and workbook won't be closed unless user fill all the dates in col. 2 in the highlighted cells.
You may use the following code for Worksheet_Change even to make sure that user only inputs the valid dates in col. C.
Right click on the Sheet Tab --> View Code --> and place the below code on the opened code window.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 3 And Target.Row > 1 Then
If Target <> "" And Not IsDate(Target) Then
MsgBox "Please input a date only.", vbCritical, "Invalid Date!"
Target = ""
Target.Select
End If
End If
End Sub
Bookmarks