VBA to randomly select teams from list of players

EinarG

New Member
Joined
Jul 3, 2014
Messages
8
Excel 2013, Win 7 Pro

Starting with column A (Player Names) and column B (Player rating - value between 0-10), I need a macro to divide the players into either 2, 4 or 6 teams randomly. Column A would have less than 100 names. Teams are named TeamA, TeamB...TeamF. TeamA competes against TeamB, etc.

I have two parameters: NumTeams = Number of teams (2,4 or 6) and MaxRatingDiff = Maximum allowed Team Rating Difference between competing teams

Each team has a rating defined as the average of the ratings of the players on that team.

Competing teams either have the same number of players or one of them (B, D or F) can have an extra player when there is an odd number of players. Example: 23 players, 4 teams would result in player counts of TeamA=6, TeamB=6, TeamC=5, TeamD=6.

I need a VBA Macro to generate approximately even strength teams with the constraint that the difference in team rating between any two competing teams does not exceed MaxRatingDiff. Alternatively, a macro that can be re-run manually (using a command button for example) by the user until he/she is satisfied with the teams. The generated teams should be in columns (Name and Rating) sorted descending by the player rating.

Thanks for help on this or any portion of it!
 
This works great! Also, thank you very much for the comments! I think I can make some small changes on my own with help from those. Thank you Eric!
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I'm getting this error way too often when using the pre-assigned 'Team' method:

Code:
 'Couldn 't find a team that can hold this group
    Tries = Tries + 1
    If Tries > 1000 Then
        MsgBox "Can't find an equal team distribution in 1000 tries.  Check to see if there are any unworkable player links, " & _
               "such as a grouping that contains 1 male A players, when the maximum number of male A players on any " & _
               "team may be only 2."
        Exit Sub
    End If
    GoTo BigLoop:

Is there anyway to fix this? Instead of this error, maybe giving the closest possible solution? I have found that this error comes up when using the new pre-assigned 'Team' grouping that you created. This error comes up when running the 'getgroups' sub when there are 'Team' grouping links that affect the ratio calculated by the 'getcounts' sub. However, any linkings must take priority over forcing all of the teams to be even.

I have made changes to the program that have actually doubled the amount of player ranks we have. So there is still a regular A male, A female, B male, etc., but there is also now one just for pitchers. So there is an A male pitcher, A female pitcher, etc. as well. This is just to ensure that there is an even spread of pitchers on every team. The problem is that these categories will only have 1-2 players assigned to them in every roster. If one of these pitcher players has a pre-assigned link (such as Team Diamonds), this error almost always comes up. If I remove the pitcher in the pre-assigned link, everything works just fine. I know this because if I remove the Team name and replace it with a random character string, the linking still works.

I'm guessing this is because there is not enough different scenarios the program can calculate, if a team name is locked in a certain spot and there are only one or two teams that get assigned a player from that category, if that makes sense.
 
Last edited:
Upvote 0
Interesting question. I'm sure you're right, the problem is that with a very limited number of pitchers, there are just a very few ways to place them. Off the top of my head, I have 2 ideas that could work.

The easiest one is just to raise the limit from 1000 to 10000. If there really is a valid combination, the program should stumble upon it eventually.

The second way would be to place the pitcher groups before the other groups. Right now the "Team" groups are placed first, then other groups. Sub-option A. If you have a linked pitcher, add the pitcher and whatever links goes with him on a "Team" group. Make sure that there is a team with counts that can handle the enlarged group. So in this scenario, you're essentially manually assigning pitchers, then letting the program assign the rest.

Sub-option B. Create another special type of group. Call a group something like: "Pitcher Group 1", etc. Then you could change the program so that it does the "Team" groups first (like now), then applies the "Pitcher" groups, then all the rest. I think that would be more likely to find a good match.

But it is possible that with all the additional constraints you're adding, there just isn't a solution. In such a case, I suppose we could save the "best" solution. What'd I suggest is if it hits that section of the program, that particular group will be marked "unplaceable" (individuals will always be placeable) and the program would continue placing everything else. When everybody has been placed or marked unplaceable, the number of unplaceable players would be counted, and if that's less than the "best" solution we've found so far, we save that solution and try again. After 1000 tries and we still haven't gotten a solution, we print out the best solution, the teams we set up, plus a list of the unplaced players, which you'd then have to manually handle somehow.

Just some options to consider!
 
Upvote 0
Interesting question. I'm sure you're right, the problem is that with a very limited number of pitchers, there are just a very few ways to place them. Off the top of my head, I have 2 ideas that could work.

The easiest one is just to raise the limit from 1000 to 10000. If there really is a valid combination, the program should stumble upon it eventually.

It still can't find a solution, even if I bump it up to 100,000.

The second way would be to place the pitcher groups before the other groups. Right now the "Team" groups are placed first, then other groups. Sub-option A. If you have a linked pitcher, add the pitcher and whatever links goes with him on a "Team" group. Make sure that there is a team with counts that can handle the enlarged group. So in this scenario, you're essentially manually assigning pitchers, then letting the program assign the rest.

Sub-option B. Create another special type of group. Call a group something like: "Pitcher Group 1", etc. Then you could change the program so that it does the "Team" groups first (like now), then applies the "Pitcher" groups, then all the rest. I think that would be more likely to find a good match.

I think with Sub-option A, they are better off not even using designated pitching categories. They can just as easy make manual switches to the draft results after it ran like it did before. I'm not sure I 100% understand Sub-option B. Would it be assigning pitcher groups to designated team groups?


But it is possible that with all the additional constraints you're adding, there just isn't a solution. In such a case, I suppose we could save the "best" solution. What'd I suggest is if it hits that section of the program, that particular group will be marked "unplaceable" (individuals will always be placeable) and the program would continue placing everything else. When everybody has been placed or marked unplaceable, the number of unplaceable players would be counted, and if that's less than the "best" solution we've found so far, we save that solution and try again. After 1000 tries and we still haven't gotten a solution, we print out the best solution, the teams we set up, plus a list of the unplaced players, which you'd then have to manually handle somehow.

Just some options to consider!

I'm not sure this is entirely true though. For instance I had a team linking for 1 D Male Player and 1 B Male Pitcher. The distribution showed that one team was capable of this, as one team had had a 1 in each of these categories. And if I take out the team name and use a random matching string, it works fine. There has to be something with how the pre-assigned players are assigned to the teams that are causing the issue.

Even if there was a way to point at the player causing the issue, I think it would help.

Thanks Eric!
 
Upvote 0
Hi Eric, I know this is an old post, but I couldn't run this code. I keep getting a Run-time error 13: Type mismatch

Highlighted line is this:
For i = 1 To Numplayers
TeamRating(t) = TeamRating(t) + Players(i, 2)
tc = tc + 1

Is there a working excel file for this? thanks.
 
Upvote 0
John, I'm not sure what else I can do. If you send me your email address in a PM, I'll send you mine, and you can send me your latest workbook, with your code changes and the player list, with pitchers, and I can look at it and see if there's anything I can do. No promises though, my time is tight right now.

@Usercode, the only reason I can see that you'd get that error is if you have a non-numeric value in the rating column. In that previous program, it expects scores to be numeric and in column B. Look for non-numeric values, words, or errors, and change it to a number and see if that fixes it. I wrote that a year and a half ago. I'd make some changes if I wrote it today, but it should still work.
 
Last edited:
Upvote 0
Hi Eric,Awesome,I have similar query, I need urgent solution and code for the below problem statement??? Thanks in Advance
[TABLE="class: waffle no-grid"]
<thead>[TR]
[TH="class: row-header freezebar-origin-ltr"][/TH]
[TH="class: column-headers-background"]A[/TH]
[TH="class: column-headers-background"]B[/TH]
[TH="class: column-headers-background"]C[/TH]
[TH="class: column-headers-background"]D[/TH]
[TH="class: column-headers-background"]E[/TH]
[TH="class: column-headers-background"]F[/TH]
[TH="class: column-headers-background"]G[/TH]
[TH="class: column-headers-background"]H[/TH]
[TH="class: column-headers-background"]I[/TH]
[TH="class: column-headers-background"]J[/TH]
[TH="class: column-headers-background"]K[/TH]
[TH="class: column-headers-background"]L[/TH]
[TH="class: column-headers-background"]M[/TH]
[/TR]
</thead><tbody>[TR]
[TH="class: row-headers-background"]1
[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"]Background
[/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]2
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- We are trying to automate the team selection process for different states for Ranji Tournament
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]3
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- The selection process involves using Player Statistics and some inputs to determine the ideal team composition for different states
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]4
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- This assignment will allow you to use excel automation to select cricket players for different states for Ranji trophy.
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]5
[/TH]
[TD="class: s7"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]6
[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"]Problem Statement
[/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]7
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]We need to select the best team for EACH STATE
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]8
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]Given a set of player information, some selection criteria and the required number of players at each position as input,automatically mark whether a player is selected or not for his state team
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]9
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]The worksheet should automatically handle the following changes:
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]10
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Changes in team composition (Number of Batsman, Number of Bowlers and Number of All Rounders)
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]11
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Addition of more states in the dataset
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]12
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Changes in the data set (Batting Averages / Wickets and Wicketkeeper flag)
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]13
[/TH]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]14
[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"]Data Available:
[/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]15
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]1) Player Info: Each player's info is given in the Player_Statistics sheet and contains following details:
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]16
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Player Name
[/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]17
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"]- State[/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]18
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Position (Batsman/ Bowler/ Allrounder)
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]19
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Batting Average
[/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]20
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Bowling Average (Wickets/ Match)
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]21
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- isWicketkeeper
[/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]22
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]23
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]2) Required Team Composition:
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]24
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- The required number of players at each position (batsman, bowler or allrounder)
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]25
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Please refer to Required_Team_Composition sheet
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]26
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]27
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]3) Selection Criteria:
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s9"][/TD]
[TD="class: s9"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]28
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- There has to be one wicketkeeper-batsman in the team. In case there are multiple candidate wicketkeepers in the state, the one with highest batting average is selected
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]29
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Select the remaining number of required batsmen in a decreasing order of their batting averages
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]30
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Select the required number of bowlers in the decreasing order of wickets/match
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]31
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- Select the allrounders based on the formula (Batting average + 5*wickets/match). The higher this value, the better the allrounder and needs to be chosen
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]32
[/TH]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]33
[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"]Output Required:
[/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]34
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]1) The "isSelected" flag should have an output "True/ False" for each row in "Player_statistics" sheet indicating whether a player is selected based on the criteria or not.
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]35
[/TH]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]36
[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"]Process & Instructions:
[/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]37
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4, colspan: 12"]1) To get the selected players, you should write excel formulas or VBA macros which populate the value of isSelected[/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]38
[/TH]
[TD="class: s4"][/TD]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]- If needed, you can add columns to the right of isSelected which would help you in the processing
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]39
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"]2) The submitted solution should be generic so that it should work on changing the Player Info and the required team composition
[/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]40
[/TH]
[TD="class: s4"][/TD]
[TD="class: s5 softmerge"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[TD="class: s6"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]41
[/TH]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[TD="class: s8"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]

[/TH]
[TD="class: s0 softmerge, bgcolor: #C9DAF8"][/TD]
[TD="class: s1, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s2, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[TD="class: s3, bgcolor: #C9DAF8"][/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="class: waffle"]
<thead>[TR]
[TH="class: row-header freezebar-origin-ltr"][/TH]
[TH="class: column-headers-background"]A[/TH]
[TH="class: column-headers-background"]B[/TH]
[TH="class: column-headers-background"]C[/TH]
[TH="class: column-headers-background"]D[/TH]
[TH="class: column-headers-background"]E[/TH]
[TH="class: column-headers-background"]F[/TH]
[TH="class: column-headers-background"]G[/TH]
[/TR]
</thead><tbody>[TR]
[TH="class: row-headers-background"]1
[/TH]
[TD="class: s0"]Player Name[/TD]
[TD="class: s0"]State[/TD]
[TD="class: s0"]Position[/TD]
[TD="class: s0 softmerge"]Batting Average
[/TD]
[TD="class: s0 softmerge"]Wickets / Match
[/TD]
[TD="class: s0 softmerge"]IsWicketKeeper
[/TD]
[TD="class: s1"]IsSelected[/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]2
[/TH]
[TD="class: s2"]P1[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]24[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]3
[/TH]
[TD="class: s2"]P2[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]11[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]4
[/TH]
[TD="class: s2"]P3[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]5
[/TH]
[TD="class: s2"]P4[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]45[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]6
[/TH]
[TD="class: s2"]P5[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]22[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]7
[/TH]
[TD="class: s2"]P6[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]16[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]8
[/TH]
[TD="class: s2"]P7[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]20[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]9
[/TH]
[TD="class: s2"]P8[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]16[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]10
[/TH]
[TD="class: s2"]P9[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]15[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]11
[/TH]
[TD="class: s2"]P10[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]24[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]12
[/TH]
[TD="class: s2"]P11[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]18[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]13
[/TH]
[TD="class: s2"]P12[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]5[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]14
[/TH]
[TD="class: s2"]P13[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]9[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]15
[/TH]
[TD="class: s2"]P14[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]21[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]16
[/TH]
[TD="class: s2"]P15[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]24[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]17
[/TH]
[TD="class: s2"]P16[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]33[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]18
[/TH]
[TD="class: s2"]P17[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]31[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]19
[/TH]
[TD="class: s2"]P18[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]20[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]20
[/TH]
[TD="class: s2"]P19[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]21
[/TH]
[TD="class: s2"]P20[/TD]
[TD="class: s2"]Maharashtra[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]11[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]22
[/TH]
[TD="class: s2"]P21[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]29[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]23
[/TH]
[TD="class: s2"]P22[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]46[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]24
[/TH]
[TD="class: s2"]P23[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]16[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]25
[/TH]
[TD="class: s2"]P24[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]34[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]26
[/TH]
[TD="class: s2"]P25[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]49[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]27
[/TH]
[TD="class: s2"]P26[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]30[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]28
[/TH]
[TD="class: s2"]P27[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]19[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]29
[/TH]
[TD="class: s2"]P28[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]8[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]30
[/TH]
[TD="class: s2"]P29[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]10[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]31
[/TH]
[TD="class: s2"]P30[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]8[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]32
[/TH]
[TD="class: s2"]P31[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]11[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]33
[/TH]
[TD="class: s2"]P32[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]18[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]34
[/TH]
[TD="class: s2"]P33[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]19[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]35
[/TH]
[TD="class: s2"]P34[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]11[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]36
[/TH]
[TD="class: s2"]P35[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]39[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]37
[/TH]
[TD="class: s2"]P36[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]47[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]38
[/TH]
[TD="class: s2"]P37[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]34[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]39
[/TH]
[TD="class: s2"]P38[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]44[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]40
[/TH]
[TD="class: s2"]P39[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]33[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]41
[/TH]
[TD="class: s2"]P40[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]24[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]42
[/TH]
[TD="class: s2"]P41[/TD]
[TD="class: s2"]Karnataka[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]20[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]43
[/TH]
[TD="class: s2"]P42[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]44
[/TH]
[TD="class: s2"]P43[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]24[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]45
[/TH]
[TD="class: s2"]P44[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]46
[/TH]
[TD="class: s2"]P45[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]33[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]47
[/TH]
[TD="class: s2"]P46[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]31[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]48
[/TH]
[TD="class: s2"]P47[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]33[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]49
[/TH]
[TD="class: s2"]P48[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]19[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]50
[/TH]
[TD="class: s2"]P49[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]19[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]51
[/TH]
[TD="class: s2"]P50[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]21[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]52
[/TH]
[TD="class: s2"]P51[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]53
[/TH]
[TD="class: s2"]P52[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]13[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]54
[/TH]
[TD="class: s2"]P53[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]4[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]55
[/TH]
[TD="class: s2"]P54[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]13[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]56
[/TH]
[TD="class: s2"]P55[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]21[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]57
[/TH]
[TD="class: s2"]P56[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]32[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]58
[/TH]
[TD="class: s2"]P57[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]28[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]59
[/TH]
[TD="class: s2"]P58[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]17[/TD]
[TD="class: s3"]3[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]60
[/TH]
[TD="class: s2"]P59[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]34[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]61
[/TH]
[TD="class: s2"]P60[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]44[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]62
[/TH]
[TD="class: s2"]P61[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]All Rounder[/TD]
[TD="class: s3"]28[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]63
[/TH]
[TD="class: s2"]P62[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Batsman[/TD]
[TD="class: s3"]26[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s3"]1[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]64
[/TH]
[TD="class: s2"]P63[/TD]
[TD="class: s2"]Delhi[/TD]
[TD="class: s2"]Bowler[/TD]
[TD="class: s3"]21[/TD]
[TD="class: s3"]2[/TD]
[TD="class: s3"]0


[TABLE="class: waffle"]
<thead>[TR]
[TH="class: row-header freezebar-origin-ltr"][/TH]
[TH="class: column-headers-background"]A[/TH]
[TH="class: column-headers-background"]B[/TH]
[/TR]
</thead><tbody>[TR]
[TH="class: row-headers-background"]1
[/TH]
[TD="class: s0"][/TD]
[TD="class: s0"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]2
[/TH]
[TD="class: s1 softmerge"]Per Team Composition
[/TD]
[TD="class: s2"][/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]3
[/TH]
[TD="class: s3"]Batsman[/TD]
[TD="class: s4"]4[/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]4
[/TH]
[TD="class: s3"]Bowler[/TD]
[TD="class: s4"]3[/TD]
[/TR]
[TR]
[TH="class: row-headers-background"]5
[/TH]
[TD="class: s3"]All Rounder[/TD]
[TD="class: s4"]4




[/TD]
[/TR]
</tbody>[/TABLE]

[/TD]
[TD="class: s2"]

[/TD]
[/TR]
</tbody>[/TABLE]

I just noticed that I missed your request that the teams be sorted in descending order of rating. Here's a version that includes that. I also made a few other tweaks to it, mostly adding some extra error checking and improving the sort.

Code:
Sub MakeTeams()
Dim Players(200, 3), TeamSize(10) As Integer, TeamRating(10) As Double
Dim i As Integer, r As Integer, j As Integer, c As Integer, ctr As Integer
Dim NumPlayers As Integer, NumTeams As Integer, trials As Integer
Dim t As Integer, tc As Integer, MaxRating As Double, MinRating As Double
' Written by Eric W.  1/9/2016

' How many teams?
    NumTeams = Range("D2").Value
    If NumTeams > 10 Or NumTeams < 2 Or Int(NumTeams) <> NumTeams Then
        MsgBox "The number of teams must be an integer from 2-10."
        Exit Sub
    End If
    
' Read all the players and ratings
    r = 2
    Erase Players, TeamSize, TeamRating
    
    While Cells(r, "A") <> ""
        If r > 201 Then
            MsgBox "The number of players must be under 200."
            Exit Sub
        End If
        Players(r - 1, 1) = Cells(r, "A")
        Players(r - 1, 2) = Cells(r, "B")
        If Not IsNumeric(Players(r - 1, 2)) Then
            MsgBox "One of the ratings is not a number."
            Exit Sub
        End If
        r = r + 1
    Wend
    NumPlayers = r - 2
    
' Figure out the team sizes
    If NumTeams > NumPlayers Then
        MsgBox "You must have at least 1 player per team.  Make sure there are no gaps in the player list."
        Exit Sub
    End If
    For r = 1 To NumTeams
        TeamSize(r) = Int(NumPlayers / NumTeams) + IIf(r <= (NumPlayers Mod NumTeams), 1, 0)
    Next r
    
' Make random teams
    trials = 0
    While trials < 250
        Call Shuffle(Players, NumPlayers)
        
' Figure out the team ratings
        t = 1
        tc = 1
        Erase TeamRating
        MaxRating = -1
        MinRating = 11
        For i = 1 To NumPlayers
            TeamRating(t) = TeamRating(t) + Players(i, 2)
            tc = tc + 1
            If tc > TeamSize(t) Then
                TeamRating(t) = TeamRating(t) / TeamSize(t)
                If TeamRating(t) > MaxRating Then MaxRating = TeamRating(t)
                If TeamRating(t) < MinRating Then MinRating = TeamRating(t)
                t = t + 1
                tc = 1
            End If
        Next i

' Max team rating - min team rating within the limit?
        If MaxRating - MinRating <= Cells(2, "F") Then GoTo PrintTeams
        
' Nope, try again
        trials = trials + 1
    Wend
    
    MyText = "Unable to find a valid set of teams in 250 tries." & Chr(10) & Chr(10)
    MyText = MyText & "You may try again, or try again with a higher MaxRatingDiff."
    MsgBox MyText
    Exit Sub
    
' Print the teams
PrintTeams:
    Range("I1:AP100").ClearContents
    ctr = 1
    For i = 1 To NumTeams
        c = i * 3 + 6
        Cells(1, c) = "Team " & Chr(64 + i)
        For j = 1 To TeamSize(i)
            Cells(j + 1, c) = Players(ctr, 1)
            Cells(j + 1, c + 1) = Players(ctr, 2)
            ctr = ctr + 1
        Next j
        
        With ActiveSheet.Sort
            .SortFields.Clear
            .SortFields.Add Key:=Cells(2, c + 1), Order:=xlDescending
            .SetRange Range(Cells(2, c), Cells(TeamSize(1) + 1, c + 1))
            .Apply
        End With
        Cells(TeamSize(1) + 3, c + 1) = TeamRating(i)
    Next i
    
End Sub
' This team will randomly shuffle the players
' (It's really a bad sort, but with under 100 players, it should be good enough.)
Sub Shuffle(ByRef Players, ByVal NumPlayers)

' Assign a random number to each player
    For i = 1 To NumPlayers
        Players(i, 3) = Rnd()
    Next i
    
' Now sort by the random numbers
    For i = 1 To NumPlayers
        For j = 1 To NumPlayers - i
            If Players(j, 3) > Players(j + 1, 3) Then
                a = Players(j, 1)
                b = Players(j, 2)
                c = Players(j, 3)
                Players(j, 1) = Players(j + 1, 1)
                Players(j, 2) = Players(j + 1, 2)
                Players(j, 3) = Players(j + 1, 3)
                Players(j + 1, 1) = a
                Players(j + 1, 2) = b
                Players(j + 1, 3) = c
            End If
        Next j
    Next i
    
End Sub
 
Upvote 0
Welcome to the forum.

This has the appearance of some type of school assignment. In general, people here don't like doing other people's homework. We feel it's counterproductive, and does not help the student learn the subject. An occasional hint, or answering a question about a specific part of the project is OK. (Like "how do I find the last row in the table, and read it all into an array?"). But asking someone to do the whole assignment is a bit much.

If you have some experience with programming, there are several complete, working programs in this thread that do similar functions. You should be able to adapt one of them. Your program actually looks like it would be substantially easier. The selection criteria are well-defined, there's no need to run multiple scenarios.

If you don't have programming experience, you might be better off with formulas. For example, put =D2*F2 in H2, and drag down. Then pick the maximum value in column H for each team, and you have your wicketkeeper. Next column over, use LARGE to get the largest batsmen values, excluding the wicket keeper. Next column over, same for the bowlers. Next column over, create the all-rounder formula, and one more column over, use LARGE on that. Plenty of details to work out, but that's where the learning comes in.

Incidentally, even if this weren't an assignment, it looks pretty time-consuming. People here are volunteers and have limited time. This is large enough that you might even need to hire a consultant. I don't have time enough to take this on right now.

So there are some ideas for you. Pick something and dig in. Good luck!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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