ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Counting Mondays in Date Range (https://www.excelbanter.com/excel-worksheet-functions/178217-counting-mondays-date-range.html)

nospaminlich

Counting Mondays in Date Range
 
I want to count the number of Mondays etc. in a date range. I found the
following on Chip Pearson's site...

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

Where A2 is the start date, B2 is the end and C2 is the weekday number

Whilst this does the trick I would prefer a solution which is not an array
formula. Can this be done another way e.g. with Sumproduct or similar and if
so how please?

Thanks a lot

Kewa



ryguy7272

Counting Mondays in Date Range
 
Here is one way of doing it:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A1&":"&A29)),2)={2}))
A1 = the cell with the first date
A29 = the cell with the last date
Change to suit your needs...

Regards,
Ryan---

--
RyGuy


"nospaminlich" wrote:

I want to count the number of Mondays etc. in a date range. I found the
following on Chip Pearson's site...

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

Where A2 is the start date, B2 is the end and C2 is the weekday number

Whilst this does the trick I would prefer a solution which is not an array
formula. Can this be done another way e.g. with Sumproduct or similar and if
so how please?

Thanks a lot

Kewa



Ron Rosenfeld

Counting Mondays in Date Range
 
On Thu, 28 Feb 2008 08:16:03 -0800, nospaminlich
wrote:

I want to count the number of Mondays etc. in a date range. I found the
following on Chip Pearson's site...

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

Where A2 is the start date, B2 is the end and C2 is the weekday number

Whilst this does the trick I would prefer a solution which is not an array
formula. Can this be done another way e.g. with Sumproduct or similar and if
so how please?

Thanks a lot

Kewa



The number of DOW (1= Sunday, 2 = Monday, ..., 7 = Saturday) between a start
date (A1) and an end date (A2) is :

=INT((A2-WEEKDAY(A2+1-DOW)-A1+8)/7)

(credit to Daniel M.)
--ron

Pete_UK

Counting Mondays in Date Range
 
You asked specifically for Mondays within a date range, so I'm not
sure why you need column C. Here's one way of doing it:

=INT((B2-A2)/7)+IF(MOD(B2-A2,7)+WEEKDAY(A2,2)7,1,0)

This assumes the dates are inclusive.

Hope this helps.

Pete

On Feb 28, 4:16*pm, nospaminlich
wrote:
I want to count the number of Mondays etc. in a date range. *I found the
following on Chip Pearson's site...

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

Where A2 is the start date, B2 is the end and C2 is the weekday number

Whilst this does the trick I would prefer a solution which is not an array
formula. *Can this be done another way e.g. with Sumproduct or similar and if
so how please?

Thanks a lot

Kewa



nospaminlich

Counting Mondays in Date Range
 
Thanks a lot for the very helpful replies.

ryguy7272

Counting Mondays in Date Range
 
I just noticed a little tiny issue with my function if the last date is a
Monday. Try this:
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A1&":"&A26)),1)={2}))
I changed the second to last 2 to a one and it seemed to work...

Regards,
Ryan--

--
RyGuy


"nospaminlich" wrote:

Thanks a lot for the very helpful replies.



All times are GMT +1. The time now is 04:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com