finding first MWF of week

Skrej

Board Regular
Joined
May 31, 2013
Messages
176
Office Version
  1. 365
Platform
  1. Windows
I'm trying to figure out a formula for an attendance roster that will calculate the first M/W/F of a month. Since this particular class only meets M/W/F, I'd like to generate an attendance roster that for each month (each month on separate sheet) which finds the first day of the month that's either a M/W/F, then calculate all the subsequent M/W/F days, skipping over weekends, etc. The in the row above, calculate which day of the week that date is

Here's a partially completed example of what September 2019 would look like:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Mon[/TD]
[TD]Wed[/TD]
[TD]Friday[/TD]
[TD]Mon[/TD]
[TD]Wed[/TD]
[TD]Friday[/TD]
[TD]Mon[/TD]
[TD]Wed[/TD]
[TD]Fri[/TD]
[/TR]
[TR]
[TD]9/2[/TD]
[TD]9/4[/TD]
[TD]9/6[/TD]
[TD]9/9[/TD]
[TD]9/11[/TD]
[TD]9/13[/TD]
[TD]9/16[/TD]
[TD]9/18[/TD]
[TD]9/20[/TD]
[/TR]
</tbody>[/TABLE]

I've been playing with some formulas I've googled, but can't quite seem to get them pieced together.

thanks in advance
 
Last edited:
It would look like this (if I've read my calendar correctly...)

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Wed
[/TD]
[TD]Fri
[/TD]
[TD]Mon
[/TD]
[TD]Wed
[/TD]
[TD]Fri
[/TD]
[TD]Mon
[/TD]
[TD]Wed
[/TD]
[TD]Fri
[/TD]
[TD]Mon
[/TD]
[TD]Wed
[/TD]
[TD]Fri
[/TD]
[TD]Mon
[/TD]
[TD]Wed
[/TD]
[/TR]
[TR]
[TD]10/2
[/TD]
[TD]10/4
[/TD]
[TD]10/7
[/TD]
[TD]10/9
[/TD]
[TD]10/11
[/TD]
[TD]10/14
[/TD]
[TD]10/16
[/TD]
[TD]10/18
[/TD]
[TD]10/21
[/TD]
[TD]10/23
[/TD]
[TD]10/25
[/TD]
[TD]10/28
[/TD]
[TD]10/30
[/TD]
[/TR]
</tbody>[/TABLE]
OK, so post 6 does this? (you just have to format the date cells with whatever date format you want)
 
Last edited:
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Thank you as well - this works nicely, too. However, I have a similar question about how it works,...
You're welcome.

The red numbers in my formulas below come from this table

1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday

In the second formula, because you were going M/W/F that is always adding 2 days and then an extra day (ie 3 days) if the previous day was a Friday, hence the blue parts of that formula.

=A2-DAY(A2)+1+AGGREGATE(15,6,7-WEEKDAY(A2-DAY(A2)+2+{2,4,6}),1)

=IF(B2="","",IF(MONTH(B2+2+(WEEKDAY(B2)=6))=MONTH($A2),B2+2+(WEEKDAY(B2)=6),""))


.. how to modify for Tue/Thu, etc.
Exactly how to modify depends on what is included with the "etc"
 
Upvote 0
You're welcome.

The red numbers in my formulas below come from this table

1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday

In the second formula, because you were going M/W/F that is always adding 2 days and then an extra day (ie 3 days) if the previous day was a Friday, hence the blue parts of that formula.

=A2-DAY(A2)+1+AGGREGATE(15,6,7-WEEKDAY(A2-DAY(A2)+2+{2,4,6}),1)

=IF(B2="","",IF(MONTH(B2+2+(WEEKDAY(B2)=6))=MONTH($A2),B2+2+(WEEKDAY(B2)=6),""))



Exactly how to modify depends on what is included with the "etc"

Sorry, I just meant how to adjust for Tue/Thur. I'll play some tomorrow when I have more time and see if I can work out how to adjust for a Tue/Thurs based on your explanation.

However, I've discovered that in Aug and Nov, it starts off with a Saturday. I'll double-check I didn't mess something up when copying the formula for those other months when I get a chance, but Feb, Mar, and June do it as well.
 
Upvote 0
However, I've discovered that in Aug and Nov, it starts off with a Saturday. I'll double-check I didn't mess something up when copying the formula for those other months when I get a chance, but Feb, Mar, and June do it as well.
No, I completely messed that first formula up. I had one working then thought I was making it better, but didn't check carefully enough. :oops:
Sorry about that.

Here are the revise MWF versions.
For row 2 I have still included the name of the day above
For the section below I have included the day name in the date formatting so we can see that they are all M/W/F

Excel Workbook
ABCDEFGHIJKLMNO
1MonWedFriMonWedFriMonWedFriMonWedFriMon
215/09/20192-Sep-194-Sep-196-Sep-199-Sep-1911-Sep-1913-Sep-1916-Sep-1918-Sep-1920-Sep-1923-Sep-1925-Sep-1927-Sep-1930-Sep-19
3
415/10/2019Wed 2-Oct-19Fri 4-Oct-19Mon 7-Oct-19Wed 9-Oct-19Fri 11-Oct-19Mon 14-Oct-19Wed 16-Oct-19Fri 18-Oct-19Mon 21-Oct-19Wed 23-Oct-19Fri 25-Oct-19Mon 28-Oct-19Wed 30-Oct-19
515/11/2019Fri 1-Nov-19Mon 4-Nov-19Wed 6-Nov-19Fri 8-Nov-19Mon 11-Nov-19Wed 13-Nov-19Fri 15-Nov-19Mon 18-Nov-19Wed 20-Nov-19Fri 22-Nov-19Mon 25-Nov-19Wed 27-Nov-19Fri 29-Nov-19
615/12/2019Mon 2-Dec-19Wed 4-Dec-19Fri 6-Dec-19Mon 9-Dec-19Wed 11-Dec-19Fri 13-Dec-19Mon 16-Dec-19Wed 18-Dec-19Fri 20-Dec-19Mon 23-Dec-19Wed 25-Dec-19Fri 27-Dec-19Mon 30-Dec-19
715/01/2020Wed 1-Jan-20Fri 3-Jan-20Mon 6-Jan-20Wed 8-Jan-20Fri 10-Jan-20Mon 13-Jan-20Wed 15-Jan-20Fri 17-Jan-20Mon 20-Jan-20Wed 22-Jan-20Fri 24-Jan-20Mon 27-Jan-20Wed 29-Jan-20Fri 31-Jan-20
815/02/2020Mon 3-Feb-20Wed 5-Feb-20Fri 7-Feb-20Mon 10-Feb-20Wed 12-Feb-20Fri 14-Feb-20Mon 17-Feb-20Wed 19-Feb-20Fri 21-Feb-20Mon 24-Feb-20Wed 26-Feb-20Fri 28-Feb-20
915/03/2020Mon 2-Mar-20Wed 4-Mar-20Fri 6-Mar-20Mon 9-Mar-20Wed 11-Mar-20Fri 13-Mar-20Mon 16-Mar-20Wed 18-Mar-20Fri 20-Mar-20Mon 23-Mar-20Wed 25-Mar-20Fri 27-Mar-20Mon 30-Mar-20
1015/04/2020Wed 1-Apr-20Fri 3-Apr-20Mon 6-Apr-20Wed 8-Apr-20Fri 10-Apr-20Mon 13-Apr-20Wed 15-Apr-20Fri 17-Apr-20Mon 20-Apr-20Wed 22-Apr-20Fri 24-Apr-20Mon 27-Apr-20Wed 29-Apr-20
1115/05/2020Fri 1-May-20Mon 4-May-20Wed 6-May-20Fri 8-May-20Mon 11-May-20Wed 13-May-20Fri 15-May-20Mon 18-May-20Wed 20-May-20Fri 22-May-20Mon 25-May-20Wed 27-May-20Fri 29-May-20
1215/06/2020Mon 1-Jun-20Wed 3-Jun-20Fri 5-Jun-20Mon 8-Jun-20Wed 10-Jun-20Fri 12-Jun-20Mon 15-Jun-20Wed 17-Jun-20Fri 19-Jun-20Mon 22-Jun-20Wed 24-Jun-20Fri 26-Jun-20Mon 29-Jun-20
1315/07/2020Wed 1-Jul-20Fri 3-Jul-20Mon 6-Jul-20Wed 8-Jul-20Fri 10-Jul-20Mon 13-Jul-20Wed 15-Jul-20Fri 17-Jul-20Mon 20-Jul-20Wed 22-Jul-20Fri 24-Jul-20Mon 27-Jul-20Wed 29-Jul-20Fri 31-Jul-20
1415/08/2020Mon 3-Aug-20Wed 5-Aug-20Fri 7-Aug-20Mon 10-Aug-20Wed 12-Aug-20Fri 14-Aug-20Mon 17-Aug-20Wed 19-Aug-20Fri 21-Aug-20Mon 24-Aug-20Wed 26-Aug-20Fri 28-Aug-20Mon 31-Aug-20
List MWF 2




Sorry, I just meant how to adjust for Tue/Thur.
So Tue/Thu would look like this.
Only needs to go across to column K this time.
However, this time we need to add 3 extra days (on top of the normal 2) if the previous date was a Thursday (adding 2 gets to Saturday and then need 3 more to get from there to the following Tuesday).

Excel Workbook
ABCDEFGHIJK
1TueThuTueThuTueThuTueThu
215/09/20193-Sep-195-Sep-1910-Sep-1912-Sep-1917-Sep-1919-Sep-1924-Sep-1926-Sep-19
3
415/10/2019Tue 1-Oct-19Thu 3-Oct-19Tue 8-Oct-19Thu 10-Oct-19Tue 15-Oct-19Thu 17-Oct-19Tue 22-Oct-19Thu 24-Oct-19Tue 29-Oct-19Thu 31-Oct-19
515/11/2019Tue 5-Nov-19Thu 7-Nov-19Tue 12-Nov-19Thu 14-Nov-19Tue 19-Nov-19Thu 21-Nov-19Tue 26-Nov-19Thu 28-Nov-19
615/12/2019Tue 3-Dec-19Thu 5-Dec-19Tue 10-Dec-19Thu 12-Dec-19Tue 17-Dec-19Thu 19-Dec-19Tue 24-Dec-19Thu 26-Dec-19Tue 31-Dec-19
715/01/2020Thu 2-Jan-20Tue 7-Jan-20Thu 9-Jan-20Tue 14-Jan-20Thu 16-Jan-20Tue 21-Jan-20Thu 23-Jan-20Tue 28-Jan-20Thu 30-Jan-20
815/02/2020Tue 4-Feb-20Thu 6-Feb-20Tue 11-Feb-20Thu 13-Feb-20Tue 18-Feb-20Thu 20-Feb-20Tue 25-Feb-20Thu 27-Feb-20
915/03/2020Tue 3-Mar-20Thu 5-Mar-20Tue 10-Mar-20Thu 12-Mar-20Tue 17-Mar-20Thu 19-Mar-20Tue 24-Mar-20Thu 26-Mar-20Tue 31-Mar-20
1015/04/2020Thu 2-Apr-20Tue 7-Apr-20Thu 9-Apr-20Tue 14-Apr-20Thu 16-Apr-20Tue 21-Apr-20Thu 23-Apr-20Tue 28-Apr-20Thu 30-Apr-20
1115/05/2020Tue 5-May-20Thu 7-May-20Tue 12-May-20Thu 14-May-20Tue 19-May-20Thu 21-May-20Tue 26-May-20Thu 28-May-20
1215/06/2020Tue 2-Jun-20Thu 4-Jun-20Tue 9-Jun-20Thu 11-Jun-20Tue 16-Jun-20Thu 18-Jun-20Tue 23-Jun-20Thu 25-Jun-20Tue 30-Jun-20
1315/07/2020Thu 2-Jul-20Tue 7-Jul-20Thu 9-Jul-20Tue 14-Jul-20Thu 16-Jul-20Tue 21-Jul-20Thu 23-Jul-20Tue 28-Jul-20Thu 30-Jul-20
1415/08/2020Tue 4-Aug-20Thu 6-Aug-20Tue 11-Aug-20Thu 13-Aug-20Tue 18-Aug-20Thu 20-Aug-20Tue 25-Aug-20Thu 27-Aug-20
List TueThu
 
Last edited:
Upvote 0
Solution
Thanks, this does the trick. However, I can't follow what's going on. Could you (or somebody else) sort of step through it, so I can see how to modify it for future use? For example, modify it for Tue/Thu classes. I'm guessing some of those binary looking numbers represent the days of the week.
Yes, those binary looking strings represent days of the week with the 0's being class days (workdays) and 1's being days-to-skip (non-work days). The first digit in the string represents Monday, second -- Tuesday, etc. You can get more info on the WORKDAY.INTL function from the Excel help.

The suggested formula is easy to modify for Tue/Thu classes -- you just need to replace both instances of the M/W/F set {""0111111","0101111","0101011""} with a Tue/Thu set {"1011111","1010111"}.

Hope this helps.
 
Last edited:
Upvote 0
Since I didn't quite like having to have a date in A2 due to layout preferences, I modified Peter's formulas a bit to just grab the date from the month/year cells I already will have on the sheet.

I imagine there's a better way to do it, but this works for me: I replaced every reference to A2 with a date function. Cell A6 is a month name, A5 a year


[TABLE="class: grid, width: 1000"]
<tbody>[TR]
[TD]cell[/TD]
[TD]formula[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]=MIN(DATE($A$5,MONTH(DATEVALUE($A$6&" 1")),1)-DAY(DATE($A$5,MONTH(DATEVALUE($A$6&" 1")),1))+8-WEEKDAY(DATE($A$5,MONTH(DATEVALUE($A$6&" 1")),1)-DAY(DATE($A$5,MONTH(DATEVALUE($A$6&" 1")),1))+1-{2,4,6}))[/TD]
[/TR]
[TR]
[TD]C2[/TD]
[TD]=IF(B2="","",IF(MONTH(B2+2+(WEEKDAY(B2)=6))=MONTH(DATE($A$5,MONTH(DATEVALUE($A$6&" 1")),1)),B2+2+(WEEKDAY(B2)=6),""))[/TD]
[/TR]
</tbody>[/TABLE]



Thanks so much to everyone for their suggestions and explanations.
 
Last edited:
Upvote 0
Since you have the month and year in separate cells, why aren't you using the simpler formula I posted in Message #3 for the formula in cell B2?
 
Upvote 0
Since you have the month and year in separate cells, why aren't you using the simpler formula I posted in Message #3 for the formula in cell B2?
Probably because of this ..
Cell A6 is a month name

@ Skrej
The formulas can be a lot simpler than your modifications.

Excel Workbook
ABCDE
1MonWedFriMon
22-Sep-194-Sep-196-Sep-199-Sep-19
3
4
52019
6September
List MWF 3



Excel Workbook
ABCDE
1TueThuTueThu
23-Sep-195-Sep-1910-Sep-1912-Sep-19
3
4
52019
6September
List TueThu 2
 
Upvote 0

Forum statistics

Threads
1,223,706
Messages
6,173,998
Members
452,542
Latest member
Bricklin

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