'---------------------------------------------------------------------------------------
' Procedure : finddays
' Author : mellon
' Date : 21-Aug-2016
' Purpose : This routine will return a count of the number of selected weekday (EG Thursdays)
' bewteen 2 dates.
'
'parameters:
'
'Date1 ----the starting date of the time interval
'Date2 ---- the endinig date of the time interval
'WhichDay-- integer representing a Day where 1=Sun,2=Mon,3=Tue,4=Wed,5=Thur,6=Fri,7=Sat
'Showdebug --if True will display the dates that are Whichday between Date1 and Date2
' in the immediate window
'---------------------------------------------------------------------------------------
'
Function finddays(StartDate As Date, enddate As Date, WhichDay As Integer, _
Optional Showdebug = False) As Integer
Dim tmpDate As Date
Dim NumDaysChosen As Integer
10 On Error GoTo finddays_Error
20 tmpDate = StartDate
30 Do While tmpDate <= enddate
40 tmpDate = tmpDate + 1
50 If WeekDay(tmpDate) = WhichDay Then
60 If Showdebug Then Debug.Print tmpDate
70 NumDaysChosen = NumDaysChosen + 1
80 Else
90 End If
100 i = i + 1
110 Loop
120 finddays = NumDaysChosen
130 On Error GoTo 0
140 Exit Function
finddays_Error:
150 MsgBox "Error " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure finddays of Module DateCalcs_UA"
End Function