In April 2017, Shenricus, posed a question in the Chandoo.org Forums:
“I have 24 people who each have their own score. I’ve been trying to figure out how I can divide these names into 3 even teams – or as close as possible.”
I answered with a Solver Based solution, and Bosco Yip also added to my solution with a slightly different approach.
This caused me to reconsider my first attempt and finally I posted a Final Solution, which was also a Solver based solution, but was a much more robust solution than my original solution or Bosco Yip’s solution.
This post will examine the thought process used to derive the solution and then implement that using solver.
As always a Sample file is provided so you can follow along: Download Sample File here.
Approach
Shenricus gave us a list of 24 players and a score for each player.
The players are Ranked from Best to Worst.
We have no other information as to the Sport or Score.
The question posed by Shenricus is to distribute the players into teams so that each team is “As even as possible”.
Considering that we have 24 players and need to put them into 3 teams, we will assume each team has the same number of players and hence requires 8 players.
My initial though was to setup a Delta or Difference between each Players Score and the Mean (Average of all scores).
First calculate the Average of All the Scores
Then calculate the Differences between the each players Score and the Average
Next we need to distribute each player into one of 3 teams.
Solver will put a value of 1 when a Player is in a Team, and a 0 when the player is not in a Team.
Next add a Formula to Calculate the Sum of the Variations from Mean for each Team
and Finally Sum these up
We should be able to get Solver to Minimise this value.
So lets look at how Solver is setup.
How Do Use Solver?
Solver is found in the Data, Analyze Tab.
Your screen may look different to mine depending on which version of Excel you are using and if you have your Excel window at a maximum size or not.
If you cannot see it, you may not have Solver Loaded.
How Do We Install Solver?
Right Click on any part of the Ribbon
Select Customize the Ribbon
Select Add-ins on the Left menu and
Manage Excel Add-ins in the Manage Dialog and press Go…
Finally Select Solver and Ok
Solver will now be visible in the Data, Analyze Tab
How Do We Setup Solver?
Click anywhere in the model
Goto the Data, Analyze Tab
Select Solver
The Solver Dialog is show as:
Lets look at each of the highlighted sections first and I will discuss this first as a plain English and then I will discuss how it is implemented in Solver
Solver is asking us to Set our Objective, to a Minimum, Maximum or Value, by changing some cells, Subject to some constraints.
Set Objective
Solver is asking what our objective is?
In our Even Teams example we want to minimise the variance in the average Team Scores
By Changing variable Cells
We want to achieve our objective by setting Each Player to be a Member of 1 team
That is Each player must have a 1 in a Column of Team 1, Team 2 or Team 3
Subject to the Constraints
We have a Number of Constraints that our model will be subject to
Each player must have a 1 in a Column of Team 1, Team 2 or Team 3
Each Team must have 8 players
All 24 Players must be used only once each
Each player can only be in a Team, he can’t be shared between teams
Solver operates using a number of techniques to Solve the above problem.
Simplistically it iterates values into the Variable Cells, subject to meeting the constraints.
It measures the output and re-iterates until a better solution is reached.
In Solver Speak
Lets look at how our model is setup in Solver
Objective
The Objective is to Minimise the Sum of the Team Scores
That is to Minimize Cell E27
Variable Cells
We will be changing the allocation of players into each team.
This is the Variable Cells $E$2:$G$25
Subject to the Constraints
The variable cells will be changed by Solver subject to meeting our 4 criteria defined above
a. That each team has 8 players, each cell in $E$29:$G$29 is 8
b. That each player only plays in 1 team, that is cells $E$2:$G$25 can only be 0 or 1 (binary)
c. That all 24 players are used, ie: $H$26 = 24
d. That all 24 players are used only once, each cell in $H$2:$H$25 = 1
We haven’t yet setup Conditions C or D above in our model yet
So add a Column H
H2: =Sum(E2:G2) and copy that down to Row 25
This will add the Total of each Team per Player and should be 1
And add up the total of these in H26, This is the Total of all allocated Players and should be 24
H26: =Sum(H2:H25)
In solver setup each of these sections then click Solve
After a Minute or so, Solver will return to tell you that it has found a Solution
Lets check things
Firstly we can see that
1. The sum of the Team Scores, E27, is a very small number, as we requested
2. Each player was only used once Column H, True
3. All 24 Players were used H26, True
4. Each Team has 8 players, E29:G29, True
5. Each player is not split between teams, E2:G25, True
So all our Criteria are met, however if we start to look at the solution in more detail we can see that Team 3 has been assigned the Best 8 players, where as Team 1 has mostly the worst players, Team 2 is in the middle.
Solver has solved our problem, but our problem obviously hasn’t been correctly specified.
Solver has setup 2 teams with Low Negative Scores to Offset Team3 with a High Positive score, with the overall result being a low average Team Score
If we look at the Total Scores for each Team, E31:G31

We can see that the Total Team Scores vary between 7.705 and 7.891
A spread of 0.186
What we actually need to specify is that the Variation in these Total Team Scores is Minimised. That is the spread between the 3 scores is minimised.
There are Statistical Measurements called Variance and Standard Deviation
Without going into too much detail, each is a measure of how far a set of numbers are spread out from their average value.
Refer Wikipedia Wikipedia Variance, Wikipedia Standard Deviation
Luckily we can easily calculate these using Excel
In cell E33 =STDEV.P(E31:G31)
Excel displays 0.078969
So the Standard Deviation of these 3 Team Scores is 0.0789
However we need to re-run the Solver Model with a new Objective
Firstly, reset all the players to 0, ie Players are not assigned to any Team
Select E2:G25 and type 0 Ctrl Enter
Click anywhere in the model,
Goto the Data, Analyze Tab
Select Solver
Set the Objective to $E$33
The Variable Cells and Constraints remain unchanged
Now Click Solve
After a minute or so, Solver will announce it has a New Solution
Accept that as before
Lets check things
Firstly we can see that
1. The sum of the Team Scores is a very small number, as we requested, Ok
2. Each player was only used once Column H, Ok
3. All 24 Players were used H26, Ok
4. Each Team has 8 players, E29:G29, Ok
5. Each player is not split between teams, E2:G25, Ok
If we look at the solution in more detail we can see that
The three Teams now have a spread of both good and not so good players
But the important thing to notice is that the Standard Deviation of the 3 Team Scores is now 0.001699, or 2.1% of the previous Standard Deviation.
This shows the teams are much more “Evenly” matched
Solver has solved our problem.
Bosco’s Solution
During the thread Bosco proposed an alternative, algebraic solution.
It involved distributing players according to simple rules
The team who got the Best player also took the worst player,
The next team who got the Second best player also took the second worst player
The next team who got the Third best player also took the third worst player, etc
This is shown:
We can see that it also meets all of the constraints of the model, but has a Standard Deviation 0.00368, that isn’t as low as the Solver solution 0.001699.
What are these Other Solving Methods?
When you were setting up Solver you may have noticed a dialog asking, Select a Solving Method:
The best discussion I have found on these alternative Solver Techniques is shown on the link below
http://www.engineerexcel.com/excel-solver-solving-method-choose/
Closing
We can see how Solver has been used to distribute players according to player ratings and even out teams.
Unfortunately, Shenicus never came back to the forums and so we don’t know how his teams went ?
How have you distributed players or anything else ensuring things are even ?
Let us know in the comments below:


































35 Responses to “Skip weekends while autofilling dates in excel”
[...] Original post by Chandoo [...]
Hi,
Is there any way that I will choose which are my "working days"?
means, I want to leave also Friday as a free day and not only Saturday.
Or, maybe someday I will pick Tuesday as a day off.
I need to also peek Wednessday, Thursday and Friday as days off. Also, for Tuesday, I would need to leave it off once every two weeks. Is there a way to easy achieve this, so that I won't actually add to my workload?
Hi Mihai... you can use pattern fill feature to do this. Simply follow steps in below demo.
Hi,
I am using MS Office 2007 and for some reason, it does not show me these options. It just shows me 3 options:
Copy Cell (Not sure about the exact text)
Copy with Formatting
Copy without Formatting
Any idea how to get those options up?
Regards,
Deep
@Deep : I am not so well versed with 2007, but here is how you can do this using menus:
enter first date of the series
select the range you want to fill
go to menu > edit > fill > series
in the dialog, select date as the series type and "weekdays only" option
press ok...
Let me know if this doesnt work...
Now that was FAST!!!
I tried it but unfortunately it didn't work..
Here is the screenshot:
http://img291.imageshack.us/img291/6573/excelsheetyr2.gif
This is what I tried..
I put the date in one row, in another row, added some calculations (as you can see in the image) and drag the content in other rows..
I could not find any Edit menu so i just clicked on the icon as you have shown in the 2nd image..
I hope I did the right thing...
Hmm...
there should be an edit menu as far as I know. Let me check that...
meanwhile... if it works you can use formulas to fill the series.
1. just enter the first date
2. in the 2nd row, enter a formula like =if(weekday(firstdatecell,2)=6,firstdatecell+2, firstdatecell+1)
3. copy the formula over the rest of the range...
@Deep:
you have to use the autofill handle, the small box at the lower right of the active cell. Right click on the autofill handle and drag down to the cells you want to autofill. A menu pops up showing the weekdays only option and others.
@Chandoo - Thanks but it did not work with my calculations. 🙁
@Robert - Yes, it worked this time but I guess, in my case it won't work as I want to add up the days from the column on the left. (As shown in the image)
Basically this is what I want:
1. I want to define project start date
2. There are no. of days assigned for each module
3. I want excel to calculate the date automatically. (By adding up the no. of days and deducting the weekends)
Any kind of help is appriciated.
Reagrds,
Deep
@Deep,
sorry, I misunderstood your question, I thought you would be searching for the autofill-function only (values).
If I got your request corrctly now, you could use the WORKDAY-function, returning the date before or after a specified number of workdays.
In Excel 2003 and earlier the Add-In Analysis Toolpak has to be installed, but since you are using 2007, it should work immediately.
@Deep.. as Robert suggested, Workday is what you should be using. It will calculate future date based number of working days you want to add to input date. Also, you can use this with your own list of holidays.
Thanks Robert, Chandoo.. I will try the things.. 🙂
I tried it and this time it worked.. Thanks to both of you.. you guys made my life much more easier 🙂
[...] You can also customize excel lists so that you can auto-fill, lets say bank holidays in your country or types of beer in your pub. One more auto fill trick. [...]
Hello,
I understand how to turn off the weekend values for a date fill in a regular auto fill. But, what if you are trying to create a custom one, that counts the amount of days in the formula bar, like 2 days, then 5 days, then 1 day etc etc etc, but they must be working days only and they must not include the weekends.
can that be done?
thanks!
hi..
i'm using excel 2007
I'm trying to insert current date automatically
then it suppose not to change after i save and open it on the next day.I need it to stay on the issued date.
i'm using Today function and it is not well work 4 me.
anybody can help to resolve my prob here?
please...
Hi guys,
How about if I just wanna fill up with weekend? The way I am doing now is using the function weekday and use filter to get weekend. Would appreciate if any one comes up with a better idea. Thank you very much.
Regards
Cheng
What happened to being able to indicate the series by adding a few cells and then using the autofill to copy? I can't get this to work - I need 4 rows with the same date skipping weekends.
2/6/2012
2/6/2012
2/6/2012
2/6/2012
2/7/2012
2/7/2012
2/7/2012
2/7/2012
2/8/2012
2/8/2012
2/8/2012
2/8/2012
2/9/2012
2/9/2012
2/9/2012
2/9/2012
Hi Kathy, sorry for a late comment. However, here's the solution.
1.) put your 1st desired date in the 1st 4 cells required (e.g. <cell A1:A4> 2/6/2012)
2.) put the following formula as is in the following four cell (i.e. A5:A8)
=IF(WEEKDAY(A1,2)=5,A1+3, A1+1)
=IF(WEEKDAY(A2,2)=5,A2+3, A1+1)
=IF(WEEKDAY(A2,2)=5,A2+3, A1+1)
=IF(WEEKDAY(A2,2)=5,A2+3, A1+1)
Note: "=5" denotes the number of working days in the week
"+3" denotes the number of days on weekends.
"+1" last denotes the number of days after the working date.
3.) Finally, select cells A4:A8 and then drag drown for furthur dates. The formula will skip Saturday & Sunday in the dates.
Let me know, if you want to tweak the formula as per other ways.
Kamlesh: Thanks for the formula. That was what I was looking for. It works the same in Google Docs Spreadsheets. At first I thought it didn't and did some unnecessary tweaking to make it work.
I was confused by the "IF(WEEKDAY(A2,2)" the modifier 2. I took it out and surpise, the formula didn't work right. I changed the 5 to 6 and then it worked. Turns out, (you probably know this) the default week starts with Sunday. Using 2 makes it start with Monday.
Any way, I didn't know about the Weekday function. Thanks for sharing this post.
Hi, Kamlesh, before i was using "workday" instead of "weekday" but it didn't work.
thanks for sharing the right formula.
At this moment I am going to do my breakfast, when having my breakfast
coming yet again to read further news.
Hi,
I'm using excel 2007
I'm trying to calculate a workday
4 nov 2014(a1) to 12 nov 2014(a2)
Normally i'm using Int formula to do this
=int(a2)-int(a1)
But, hey thats including weekend too... 😀
how do you calculate workday with this condition ?
and if there is not only those day, i mean in a month or two
Thanks before
sagari
@Sagari
=NETWORKDAYS.INTL(DATE(2014,11,4),DATE(2014,11,12),1)
=7
You can also include holidays into the formula by having a list of holidays in say A1:A10
Then use
=NETWORKDAYS.INTL(DATE(2014,11,4),DATE(2014,11,12),1,A1:A10)
Thanks for replying
Get #NAME? in return when using NETWORKDAYS.INTL
But get 7 with NETWORKDAYS
why ??
Hi
i had a query while making a template for one of my school daily task.
Most of the work in these template includes copy from webpage and paste in the template.
so the problem here is, whenevr me or my mates try to do ctrl+v
the format of the cell changes automatically.
I suggested them to use ctrl+alt+v (text) to paste
but they are not ok with it. they want me to make template in such a way that it should work with normal ctrl +v
Any ideas guys ?
Our working week is Tuesday to Saturday if I wish to make a sheet solely using those days is there a formula I can use ?
I need your support for date.
I wand to numbering actual working date based on date
below is expected result... so how can apply formula to get number automatically... please help me get resolve this problem... many thanks in advanced.
1 8/1/2018
2 8/2/2018
3 8/3/2018
8/4/2018
8/5/2018
4 8/6/2018
5 8/7/2018
6 8/8/2018
7 8/9/2018
8 8/10/2018
8/11/2018
8/12/2018
9 8/13/2018
10 8/14/2018
11 8/15/2018
12 8/16/2018
13 8/17/2018
8/18/2018
8/19/2018
14 8/20/2018
15 8/21/2018
16 8/22/2018
17 8/23/2018
18 8/24/2018
Dear Sir,
I want to make a series of December month which will show all the dates without Fridays.
Is it Possible sir??
Interesting question Salauddin... The built-in options in Excel can't generate dates like this. But you can use simple formulas to make up such a series.
In first cell (say A1) write the starting date (1-Dec-2019 for example). Makesure this date is not a Friday.
In the next cell (A2) write =WORKDAY.INTL(A1,1,16)
Now drag down the A2 cell to fill up dates. Stop when you reach the end of your range of dates.
If your Excel doesn't have WORKDAY.INTL(), then use the below alternative formula.
=A1+1+(WEEKDAY(A1)=5)
Thank you, Thank you very much sir. it worked perfectly & I was expecting something like that.
i want to make a template with date that skips fortnightly is it possible in excel
Hi Chandoo, I need to skip weekends from a specified list of dates.
from the below information I want to pick only the weekdays amount only along with lookup which has builder name separately.
Date Builder Units Amount
06-Jan-08 Doug 8 389
09-Feb-08 Dave 10 385
15-Mar-08 Dave 3 771
18-Apr-08 Brian 5 313
05-May-08 Larry 10 574
22-May-08 Rob 8 730
25-Jun-08 Morgan 4 471
15-Aug-08 Jones 1 548
12-Dec-08 Doug 3 323
10-Apr-09 Dave 5 712
14-May-09 Dave 9 432
10-Sep-09 Brian 6 460
31-Oct-09 Larry 3 741
18-Sep-08 Rob 8 580
25-Nov-08 Doug 6 685
29-Dec-08 Dave 2 401
24-Mar-09 Dave 10 342
04-Jul-09 Brian 8 475
21-Jul-09 Larry 3 535
07-Aug-09 Rob 3 663
26-Feb-08 Gill 10 762
22-Oct-08 Jones 5 425
08-Nov-08 Doug 1 639
27-Apr-09 Dave 4 409
27-Sep-09 Dave 4 612
01-Sep-08 Brian 6 688
17-Jun-09 Larry 10 663
24-Aug-09 Rob 5 608
23-Jan-08 Morgan 6 388
Thank you! I've been struggling with this for ages and today, thanks to this post, I finally figured that I had to customize my toolbar in order to utilise the "Fill" menu. This will make my monthly reports much, much neater