I could not figure it out , so I decided to cheat
, and write a custom function.
a couple of things you need to know.
file must be saved as an .xlxm
dates must be sorted smallest to largest on sheets
copy the code below, open vba alt & F11.
click insert then module
paste the code into it
the name of the function is rollingcount and is under userdefined functions.
I attached the file that i was working with. if you click on the cell with the formula and then Fx you can see the required arguments.
i hope this helps, and if you need anything else just let me know.
Option Explicit
Function RollingCount(WorksheetName As String, Interval As Long, Criteria As String, CriteriaCol As Long, Optional FirstDate As Range) As Long
Application.Volatile
Dim WsN As Worksheet
Dim lFinalRow As Long
Dim i As Long
Dim lTempCount As Long
Dim lMaxCount As Long
Dim dStartDate As Date
Dim dEndDAte As Date
Set WsN = ThisWorkbook.Worksheets(WorksheetName)
lFinalRow = WsN.Cells(Rows.Count, 1).End(xlUp).Row
dStartDate = CDate("1/1/" & Year(WsN.Range("A4")))
dEndDAte = dStartDate + Interval
lTempCount = 0
lMaxCount = 0
RollingCount = 0
For i = 4 To lFinalRow
Select Case WsN.Cells(i, 1).Value
Case dStartDate To dEndDAte
If (StrComp(Trim(Criteria), Trim(WsN.Cells(i, CriteriaCol).Value), vbTextCompare) = 0) Then
lTempCount = lTempCount + 1
End If
Case Else
i = i - 1
If lTempCount > lMaxCount Then
lMaxCount = lTempCount
lTempCount = 0
End If
dStartDate = dEndDAte + 1
dEndDAte = dStartDate + Interval
End Select
Next i
If lTempCount > lMaxCount Then lMaxCount = lTempCount
RollingCount = lMaxCount
End Function
Bookmarks