How many mondays, tuesdays, etc in a month

Hans810

Board Regular
Joined
Dec 1, 2005
Messages
63
Dear all,

A new challenge! Can somebody help me with the vba code or formulas for extracting the number of mondays, tuesdays, etc from a specific month in a specific year? i need this information for calculating the amount of delivery days for our clients.

Thanks in advance.

Regards from freezing Holland!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,

Try this:

=SUM(IF(WEEKDAY(A2-1+ROW(INDIRECT("1:"&TRUNC(B2-A2)+1)))=C2,1,0))

Array Formula: Confirmed with CTRL, SHIFT + ENTER, not just ENTER.

Where,
A2 = Start Date
B2 = End Date
C2 = Day to count (1 = Sunday, 2 = Monday, 3 = Tuesday etc..)

Similar formulas here: http://www.cpearson.com/excel/DateTimeWS.htm
 
Upvote 0
Run code and Insert "Month/Year" in Inputbox like:- 4/2012
Results in msgbox and starting "L1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG09Jan42
[COLOR="Navy"]Dim[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] dt [COLOR="Navy"]As[/COLOR] Date
[COLOR="Navy"]Dim[/COLOR] Nam [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] c
c = 0
Txt = Application.InputBox(prompt:="Enter Month/Year, i.e :- 4/2012", Title:="Weekdays", Type:=2)
[COLOR="Navy"]If[/COLOR] Txt = "" Or Txt = "False" [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
    dt = CDbl(DateValue("1/" & Txt))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
        [COLOR="Navy"]If[/COLOR] IsDate(dt) [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]While[/COLOR] Val(Month(dt)) = Val(Split(Txt, "/")(0))
                dt = DateAdd("d", c, CDbl(DateValue("1/" & Txt)))
                Nam = WeekdayName(Weekday(dt), , vbSunday)
                c = c + 1
                [COLOR="Navy"]If[/COLOR] Not .Exists(Nam) [COLOR="Navy"]Then[/COLOR]
                    .Add Nam, 1: Temp = Nam
                [COLOR="Navy"]Else[/COLOR]
                    .Item(Nam) = .Item(Nam) + 1
                    Temp = Nam
                [COLOR="Navy"]End[/COLOR] If
            Wend
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Dim[/COLOR] K
[COLOR="Navy"]Dim[/COLOR] nTxT [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .Keys
    [COLOR="Navy"]If[/COLOR] K = Temp [COLOR="Navy"]Then[/COLOR] .Item(K) = .Item(K) - 1
        nTxT = nTxT & K & " // " & .Item(K) & Chr(10)
[COLOR="Navy"]Next[/COLOR] K
Range("L1").Resize(.Count, 2) = Application.Transpose(Array(.Keys, .Items))
MsgBox nTxT
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
A2 = Start Date
B2 = End Date
C2 = Day to count (1 = Sunday, 2 = Monday, 3 = Tuesday etc..)

Given that setup this non-array formula will produce the same result for any period

=INT((WEEKDAY(A2-C2)+B2-A2)/7)

Specifically for a calendar month you can also use this formula where the end date isn't required

=4+(DAY(A2+34)< WEEKDAY(A2-C2))

Assumes A2 is 1st of month....
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top