Count # of Days in a Month
On 4 May 2007 11:12:35 -0700, DF wrote:
Does someone know off hand a function that would count the number of
individual days in a given month? For example, how many Mondays in
May 2007, how many Tuesdays, etc... I've searched the help files and
did not find anything I could use. Thanks in advance for your help.
--DFruge
=4+(DAY(A1-DAY(A1)+1-WEEKDAY(A1-DAY(A1+DOW))+35)7)
Where DOW is the Day Of the Week with
Monday = 1
Tuesday = 2
etc.
Or, in VBA, something like:
========================================
Option Explicit
Sub WDinMonth()
Dim DOW As Long
Dim Dt As Date
Dt = DateValue(InputBox("Enter Month and Year"))
Debug.Print "Number of Weekdays in " & Format(Dt, "mmm yyyy")
For DOW = 1 To 7
Debug.Print _
Application.WorksheetFunction.Choose(DOW, _
"Monday", "Tuesday", "Wednesday", "Thursday", _
"Friday", "Saturday", "Sunday"), _
5 + (Day(Dt - Day(Dt) + 1 - Weekday(Dt - Day(Dt + DOW)) + 35) < 7)
Next DOW
End Sub
====================================
Note that in VBA the comparison in the formula is reversed because, in VBA,
TRUE = -1 and FALSE = 0
--ron
|