I was playing around with something like Mark's
Sub test() MsgBox CountMondays(#6/7/2016#, #6/10/2016#) MsgBox CountMondays(#6/6/2016#, #6/20/2016#) MsgBox CountMondays(#6/7/2016#, #6/20/2016#) MsgBox CountMondays(#6/6/2016#, #6/19/2016#) MsgBox CountMondays(#1/1/2016#, #12/31/2016#) End Sub Function CountMondays(ByVal StartingDate As Date, ByVal EndingDate As Date) As Long Dim d As Date, D1 As Date, D2 As Date Dim n As Long If Weekday(StartingDate) = vbMonday Then D1 = StartingDate Else D1 = StartingDate - Weekday(StartingDate) + vbMonday + 7 End If If Weekday(EndingDate) = vbMonday Then D2 = EndingDate Else D2 = EndingDate - Weekday(EndingDate) + vbMonday - 7 End If If D2 => D1 Then CountMondays = 1 + (CLng(D2) - CLng(D1)) \ 7 Else CountMondays = 0 End If End Function




Reply With Quote