' Return the number of Mondays in this month.
Private Function NumMondays(ByVal month_name As String, _
ByVal year_name As String) As Integer
Dim i As Integer
Dim num_mondays As Integer
Dim test_date As Date
Dim orig_month As Integer
' Get the first day of the month.
test_date = CDate(month_name & " 1, " & year_name)
' Get the first Monday.
Select Case Weekday(test_date)
Case vbMonday
' Leave the date unchanged.
Case vbTuesday
test_date = DateAdd("d", 6, test_date)
Case vbWednesday
test_date = DateAdd("d", 5, test_date)
Case vbThursday
test_date = DateAdd("d", 4, test_date)
Case vbFriday
test_date = DateAdd("d", 3, test_date)
Case vbSaturday
test_date = DateAdd("d", 2, test_date)
Case vbSunday
test_date = DateAdd("d", 1, test_date)
End Select
' Count the Mondays.
orig_month = Month(test_date)
Do
num_mondays = num_mondays + 1
test_date = DateAdd("ww", 1, test_date)
Loop While (Month(test_date) = orig_month)
NumMondays = num_mondays
End Function
|