Hello Biff,
I believe I "invented" that formula so I really ought to know how it works
– I certainly do but I’ve never perhaps explained it as well as I could so here's my best attempt……
Starting with this version
=INT((WEEKDAY(J6-2)+K6-J6)/7)
That counts Mondays between J6 and K6 inclusive – assumes K6 >= J6
The idea that I started with was that there was no need to examine every date in a range to see how many of those were Mondays – I knew that if there were 7 days in the range there would be 1 Monday – if there were 14 days then there must be 2. Now if the range wasn’t divisible by 7 then it was trickier – if there were 8 days in the range then there would be 1 Monday or 2……which one depends on the start date (or end date). In fact if there were 8 days in the range then there could only be 2 Mondays if the start date was a Monday….if there were 9 days in the range then there could only be two Mondays if one of the first two days was a Monday (i.e. start date should be Sunday or Monday)…..if there were 10 days in the range then start date would need to be Saturday, Sunday or Monday…….etc.
So I can quantify that with a formula, if I subtract the start from the end and add 1 to get the number of days….then divide by 7 and round down that will give me the minimum number of Mondays, i.e.
=INT((1+K6-J6)/7)
But now I need to factor in an adjustment based on start date, by having a Monday start date I have a whole week’s worth of Mondays in one day (effectively), so I need to add another 6 when Monday is the start date…..if Sunday is the start date I want to add another 5, if Saturday is the start date I add 4…..so to do that (combined with the +1 already in there) I can use the WEEKDAY function offset accordingly, e.g. WEEKDAY(J6-2) will give me 7 on a Monday, 6 on a Sunday etc….so the formula becomes:
=INT((WEEKDAY(J6-2)+K6-J6)/7)
[Another way to look at this is that you are effectively expanding the size of the date range backwards to start immediately after the previous Monday....by doing that you never add any Mondays but you "normalise" the date range so that it always starts on the same day of the week.........]
Clearly 2 works for a Monday, change that to 1 for Sun through to 7 (or 0) for Sat…and you can use any combination in an array and then SUMMED, e.g. to count Mondays and Fridays in the range
=SUM(INT((WEEKDAY(J6-{2,6})+K6-J6)/7))
Note that J6 is repeated twice in the formula, K6 only once, so if you have some sort of complex formula to calculate the start date….and a less complex one for end date then it might be a good idea to use a formula that will calculate based on the weekday of the end date (K6), so this formula uses a similar logic to count Mondays between J6 and K6
=INT((8-WEEKDAY(K6-1)+K6-J6)/7)
regards, barry