'This sub must be installed in the code pane for the calendar worksheet. It will not work at all if installed anywhere else.
Private Sub Worksheet_Activate()
Dim ws As Worksheet, wsCalendar As Worksheet
Dim rg As Range, rgDest As Range
Dim n As Long
Application.ScreenUpdating = False
Set wsCalendar = Worksheets("Calendar")
wsCalendar.Rows(2).Resize(wsCalendar.Rows.Count - 1).Delete
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "Calendar", "Home", "Working Space" 'Ignore these worksheets
Case Else
With ws
Set rg = .Range("B4").Resize(.UsedRange.Rows.Count, 5) 'Look at columns B:F, starting in row 4
If (Not Intersect(rg, .UsedRange) Is Nothing) And (rg.Cells(1, 2) <> "") Then
rg.AutoFilter Field:=2, Criteria1:="<=" & (Date + 5), Operator:=xlAnd, Criteria2:=">=" & (Date - 5)
Set rgDest = wsCalendar.Cells(wsCalendar.UsedRange.Rows.Count + wsCalendar.UsedRange.Row, 2)
.AutoFilter.Range.Copy rgDest
n = wsCalendar.UsedRange.Rows.Count + wsCalendar.UsedRange.Row - rgDest.Row
rgDest.Offset(0, -1).Resize(n, 1).Value = ws.Name
rgDest.Rows(1).EntireRow.Delete
.Range("B4").AutoFilter
End If
End With
End Select
Next
Application.ScreenUpdating = True
End Sub
|