generate a set of cells with 4 weekdays in them

magicmusic

New Member
Joined
Sep 2, 2011
Messages
8
I teach college music - and need to consistently make and give students a rehearsal plan for a choir which meets 4 of the 5 days (M, W, Th, F) each week. Each plan is usually different lengths of time - sometimes it's a couple weeks, sometimes a whole quarter (10 weeks).

I currently type each date manually for each separate plan - but would like to automate the process.

I would like to be able to generate a set of vertical cells which would contain x amount of days - where x is the amount of class meeting days between date entry 1 and date entry 2.

I would like each cell formatted with mo/day (day first letter),

for example 9/6 (T)

I have been reading the Mr Excel archives for date ideas, and have seen formulas to return #of days in month, 1st Monday of a Month, how many calendar days between dates, etc. I also have been introduced to the workday function - which seems pretty helpful in this case.

I've messed with Macros and VB - though I'm the kind of "programmer" who, left to my own devices, usually needs 10 lines of code where two would do if generated by an expert.

My idea is for a sheet that looks like this:
A2 - begin date
B2 - end date
C2 - amount of class days between A1&B1 (4/week, M, W, Th, F)

A4, A5, A6 . . . (through the number returned in C1)



Thus - the result look something like below:

*********************************

BeginDate | End Date | ClassMeetings
9/15/2011 | 11/4/2011 | 30

9/15 (Th)
9/16 (F)
9/19 (M)
9/21 (W)
|
|
11/4 (F)

**********************************
(no Tuesday meeting)

Again, this list twould be a different length each time, depending upon begin and end date . . .

Thanks in advance for getting me started in the right direction!

Gary
 
@ Jim

Might I suggest a variation on your solution?

In A5
Code:
=IF(MAX($A$4:$A4)>=$B$2,"",IF(OR(B4=" (W)",B4=" (Th)"),A4+1,IF(B4=" (F)","",IF(B4=" (M)",A4+2,A3+3))))

Then in C2 replace the volatile formula with
Code:
=COUNT(A:A)-1
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Gary

I was checking the thread but I see that your problem is already solved.

Just about Q3

3) What formula will return the # of class meetings in A1 and B1 (Marcol's solution seems to return that number after the fact, by counting hidden column B) I'd prefer the number "up front" and automatically generated.

To calculate the total number of class meetings "up front", that I understand as just using the start and end dates, an alternative is to count them directly.

=SUMPRODUCT(0+(WEEKDAY(ROW(INDIRECT(A2&":"&B2)))={2,4,5,6}))
 
Upvote 0
Jim,

I've put in your newest suggestion. Since you didn't list the A4 formula, I put the same formula for A4 as you previously suggested. I've also put Marcol's variation on your suggestion to which you said "nice".

The lists work - with blank rows separating the weeks. Thanks!

Since you did program an "error message" (BeginDate is a Sunday, Tuesday, or Saturday) for BeginDate, I thought I'd point out that if the EndDate is not "valid" (meaning it is a Sun, Tues, or Sat) the sheet adds to the list the next "valid" date.

So for example, if I enter
9/15/2011 for BeginDate in A2 and
9/20/2011 for EndDate in B2, (A Tuesday)

rather than the list going up to 9/19/ (Monday), the list is populated with 9/15, 9/16 skips a line (as it's supposed to) and then has 9/19 with 9/21 (Wed) added . . .

The same happens if I enter a Sat or Sun - it puts the next Monday in.

I'm amazed and grateful for the comments from everyone who has made suggestions. And I can deal with that very minor issue - but since you included a simple error catcher for the BeginDate- I thought I'd let you know what happens with a "false" entry for the EndDate

Marcol - I tried to insert the VB module - but I don't know how to insert the module into Sheet1. I inserted it into the Module window - but don't know how to call it, or save it to Sheet1. Sorry!

I also don't know how to apply validation. I do like to learn, however, if you tell me how to do that.

To Jim, and PGC - I must admit, I would love to know how one of the long formulas work by having one of them explained - but I know time is precious and I've usurped enough of it already.

Anyway - thanks, all - I've got a list generator which will save me a lot of time for my choir rehearsal plans!

Best,
Gary
 
Upvote 0
Gary,

Glad it works for you. I was a full-time musician during ALL my high school years.
I loved music MORE than anything else. Have gotten away from it over the years, but
still, I love it.

Jim
 
Upvote 0
More one way:

Note: with Marcol's C2 formula.

Data Validation in A2
Configuration tab
Allow box: Custom
Formula box: =AND(WEEKDAY(A2,2)<>2,WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7)

Input message tab
Title box: Begin Date
Input message box: Type a date - m/d/yyyy only for this weekday: Mon, Wed, Thu or Fri

Error Alert tab
Style box: Stop
Title box: Begin Date
Error message box: Invalid Date - Your date is Sat, Mon or Tue

Data Validation in B2
Configuration tab
Allow box: Custom
Formula box: =AND(WEEKDAY(B2,2)<>2,WEEKDAY(B2,2)<>6,WEEKDAY(B2,2)<>7)

Input message tab
Title box: End Date
Input message box: Type a date - m/d/yyyy only for this weekday: Mon, Wed, Thu or Fri

Error Alert tab
Style box: Stop
Title box: End Date
Error message box: Invalid Date - Your date is Sat, Mon or Tue

Now, the formulas:

Excel 2007<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">Begin Date </TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">End Date </TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">ClassMeetings</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: center">9/15/2011</TD><TD style="TEXT-ALIGN: center">11/4/2011</TD><TD style="TEXT-ALIGN: center">30</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: center"></TD><TD style="TEXT-ALIGN: center"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">4</TD><TD style="TEXT-ALIGN: right">9/15 Thu</TD><TD>9/15 (Th)-1</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">5</TD><TD style="TEXT-ALIGN: right">9/16 Fri</TD><TD>9/16 (F)-2</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">6</TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">7</TD><TD style="TEXT-ALIGN: right">9/19 Mon</TD><TD>9/19 (M)-3</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">8</TD><TD style="TEXT-ALIGN: right">9/21 Wed</TD><TD>9/21 (W)-4</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">9</TD><TD style="TEXT-ALIGN: right">9/22 Thu</TD><TD>9/22 (Th)-5</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">10</TD><TD style="TEXT-ALIGN: right">9/23 Fri</TD><TD>9/23 (F)-6</TD><TD style="TEXT-ALIGN: right"></TD></TR></TBODY></TABLE>Sheet2


<TABLE style="BORDER-BOTTOM: black 2px solid; BORDER-LEFT: black 2px solid; PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 0.4em; PADDING-RIGHT: 0.4em; BORDER-COLLAPSE: collapse; BORDER-TOP: black 2px solid; BORDER-RIGHT: black 2px solid; PADDING-TOP: 0.4em" rules=all cellPadding=2 width="85%"><TBODY><TR><TD style="PADDING-BOTTOM: 6px; PADDING-LEFT: 6px; PADDING-RIGHT: 6px; PADDING-TOP: 6px">Worksheet Formulas<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; TEXT-ALIGN: center; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2 width="100%"><THEAD><TR style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH width=10>Cell</TH><TH style="TEXT-ALIGN: left; PADDING-LEFT: 5px">Formula</TH></TR></THEAD><TBODY><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>C2</TH><TD style="TEXT-ALIGN: left">=COUNT(A:A)-1</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>A4</TH><TD style="TEXT-ALIGN: left">=IF(ROWS(A$4:A4)=1,A$2,IF(MAX(A$3:A3)=B$2,"",IF(WEEKDAY(MAX(A3),2)=5,"",MAX(A$3:A3)+CHOOSE(WEEKDAY(MAX(A$3:A3),2),2,,1,1,3))))</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>B4</TH><TD style="TEXT-ALIGN: left">=TEXT(A4,"m/d")&" "&CHOOSE(WEEKDAY(MAX(A4),2),"(M)","","(W)","(Th)","(F)","")&IF(A4="","","-"&COUNT(A$4:A4))</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Markmzz
 
Upvote 0
Anothers formulas for the Data Validation in A2 and B2:

=AND(WEEKDAY(A2,2)<>2,WEEKDAY(A2,2)<6)

=AND(WEEKDAY(B2,2)<>2,WEEKDAY(B2,2)<6)

Markmzz
 
Upvote 0
Hi magicmusic

To use the VBa possibility
1/. In Excel right click on the tab of the sheet you want to use the macro in.
Select View code this will open the VBa editor with the sheet module.
2/. Paste all of the given code in the resultant pane/window.
3/. Save the file and close the VBa editor

Then when you change the dates in A2:B2 the code will automatically trigger.

To set the data validation
1/. Select A2 then Data > Data Validation .... Settings
Allow:= Date
Data:= greater than
Start date:= 01/01/2000 (or your choice.) ... Press okay.

1/. Select B2 then Data > Data Validation .... Settings
Allow:= Custom
Formula:=
Code:
=B2>=A2
With the Error Alert Tab
Style:= Stop
Title:= Invalid Date
Error message:= Must be greater or equal to start date.

or use some of Marks' suggestions.

See a sample from my skydrive magicmusic _Book2
 
Upvote 0
A small modification:

Excel 2003 - Data menu/Validation

Excel 2007 - Data tab/Data tools/Data validation/Data Validation

Data Validation in A2
Configuration tab
Allow box: Custom
Formula box: =CHOOSE(WEEKDAY(A2,2),1,0,1,1,1,0,0)

Input message tab
Title box: Begin Date
Input message box: Type a date - m/d/yyyy only for this weekday: Mon, Wed, Thu or Fri

Error Alert tab
Style box: Stop
Title box: Begin Date
Error message box: Invalid Date - Your date is Sat, Mon or Tue

Data Validation in B2
Configuration tab
Allow box: Custom
Formula box: =AND(WEEKDAY(B2,2)<>2,WEEKDAY(B2,2)<6,B2>A2)

Input message tab
Title box: End Date
Input message box: Type a date - m/d/yyyy only for this weekday: Mon, Wed, Thu or Fri and large then Begin Date.

Error Alert tab
Style box: Stop
Title box: Begin Date
Error message box: Invalid Date - Your date is Sat, Mon or Tue or less then or equal Begin Date

The formulas:

Excel 2007<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">Begin Date </TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">End Date </TD><TD style="TEXT-ALIGN: center; FONT-WEIGHT: bold">ClassMeetings</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: center">9/15/2011</TD><TD style="TEXT-ALIGN: center">11/4/2011</TD><TD style="TEXT-ALIGN: center">30</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: center"></TD><TD style="TEXT-ALIGN: center"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">4</TD><TD style="TEXT-ALIGN: right">9/15 Thu</TD><TD>9/15 (Th)</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">5</TD><TD style="TEXT-ALIGN: right">9/16 Fri</TD><TD>9/16 (F)</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">6</TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">7</TD><TD style="TEXT-ALIGN: right">9/19 Mon</TD><TD>9/19 (M)</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">8</TD><TD style="TEXT-ALIGN: right">9/21 Wed</TD><TD>9/21 (W)</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">9</TD><TD style="TEXT-ALIGN: right">9/22 Thu</TD><TD>9/22 (Th)</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">10</TD><TD style="TEXT-ALIGN: right">9/23 Fri</TD><TD>9/23 (F)</TD><TD style="TEXT-ALIGN: right"></TD></TR></TBODY></TABLE>Sheet3


<TABLE style="BORDER-BOTTOM: black 2px solid; BORDER-LEFT: black 2px solid; PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 0.4em; PADDING-RIGHT: 0.4em; BORDER-COLLAPSE: collapse; BORDER-TOP: black 2px solid; BORDER-RIGHT: black 2px solid; PADDING-TOP: 0.4em" rules=all cellPadding=2 width="85%"><TBODY><TR><TD style="PADDING-BOTTOM: 6px; PADDING-LEFT: 6px; PADDING-RIGHT: 6px; PADDING-TOP: 6px">Worksheet Formulas<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; TEXT-ALIGN: center; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2 width="100%"><THEAD><TR style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH width=10>Cell</TH><TH style="TEXT-ALIGN: left; PADDING-LEFT: 5px">Formula</TH></TR></THEAD><TBODY><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>C2</TH><TD style="TEXT-ALIGN: left">=COUNT(A:A)-1</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>A4</TH><TD style="TEXT-ALIGN: left">=IF(ROWS(A$4:A4)=1,A$2,IF(MAX(A$3:A3)=B$2,"",IF(WEEKDAY(MAX(A3),2)=5,"",MAX(A$3:A3)+CHOOSE(WEEKDAY(MAX(A$3:A3),2),2,,1,1,3))))</TD></TR><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>B4</TH><TD style="TEXT-ALIGN: left">=IF(A4="","",TEXT(A4,"m/d")&" ("&CHOOSE(WEEKDAY(A4,2),"M",,"W","Th","F")&")")</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Markmzz
 
Upvote 0
Marcol, Thanks for the help on data validation and entering the vb code. I know a little about programming - I just didn't realize excel had a data validation feature - I used to do that with macro code in early versions.

I put your vb code in - and it worked. Unless I'm doing something incorrectly, once I run it - if I change dates, it doesn't change whatever list I generated first. So I get one chance for some reason. What am I missing?

markmzz - I really like your formulas. And - you read my mind: I like to have the class meetings counted up as well. Your solution works really well!

Could you show me what to adjust in the A4 and B4 formulas to do the same for a M W F class, and a T Th class? I also teach those and generate date lists for them as well.

I looked up MAX, WEEKDAY, and CHOOSE - and understand them a bit. My guess (since this is somewhat above me) is it's somehow adjusting your choose function with the weekday choice (2,,1,1,3) parameters (I do understand the 1,2,3 parameters for WEEKDAY function - just not how to use them to only get MWF or T Th)

Jim - I am the Dir. of Choral Studies at a University - I direct 3 choirs and oversee a couple more. I see there's a way to private message on this forum. I don't want to spam you - but if you are interested in seeing a couple of professionally produced videos of my top choir (classical music), write me for a link. No problem if not!

To all of you - your solutions are as artistic as singing a good phrase. I enjoy computers and watching experts make them "sing".

Thanks for your continuing comments!

Gary
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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