+ Reply to Thread
Results 1 to 8 of 8

Sort

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Here
    MS-Off Ver
    2016
    Posts
    10

    Sort

    I need a macro that takes a two column table of player names and averages (bowling) and sorts them into a specified # of teams so the resulting average per team is equal or as close to equal as possible. We don't have static teams, we assign new teams each week by average.

    Considerations:
    - always between 2 to 5 teams depending on the total # of players each week
    - we use "mystery" bowlers to even out teams (i.e. if there are 11 players, we have 1 mystery player as the 12th and have 4 teams of 3).
    - mystery bowler can be called Mystery1 and Mystery2 depending on how many are needed (rarely 2)
    - mystery bowler would be assigned an average that equals the assigned teams average
    - if possible, ability to set # of teams (e.g. if we know we have 11 players, we set it to 3 teams of 4 OR 4 teams of 3 and then run the macro)

    Example team below.

    Player Overall Average
    Jack 185
    Jill 158
    Chris 149
    Pete 172
    Scott 159
    John 154
    Mihir 167
    Sally 162
    James 156
    Hank 165
    Perry 166

    Thanks for any help, I have been struggling with this one for a long time!

  2. #2
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: Sort

    You might try sorting the players by their average. Then start going down the list from top to bottom putting them in team first going from highest average then the next player would be from from the bottom lowest to highest. Then repeat until all players have been assigned.

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,016

    Re: Sort

    Sort macro:

    Please Login or Register  to view this content.
    There is also a formula version in the workbook, Column C1, pasted and drag down.
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Sort

    I think this will do what you want. The players in columns A & B will be sorted by average. Make sure that only players and their scores are in these two columns and that the rows of data are contiguous (no blank rows in the data range).

    Enter in the number of teams in cell E1 and click on the Assign Teams Button.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    Here
    MS-Off Ver
    2016
    Posts
    10

    Re: Sort

    Sorry for the late reply, and thanks for yours! From a formatting perspective, this is exactly what I need!

    However, when looking at a final team I notice that since these are in order of average, the team average will ultimately get skewed downward the higher the team #. For example, I put in 12 players (I added one more player (Nate 130 avg) into the table in the original post) and sorted for 4 teams using the macro.

    The end result is that each team has a lower overall average as you progress. My goal is to sort the teams so the team averages are either equal, or as close to equal as they can get.

    Is there any way to do that in this macro? Thanks in advance for your help!

    (sorry for the format of this table, for some reason it would not let me post an html table)

    Team 1 Team 2 Team 3 Team 4
    Jack Pete Mihir Perry
    Hank Sally Scott Jill
    James John Chris Nate
    Team Average: 169 163 158 151 (note averages going down, need the macro to sort players so the team averages are as close to the same as possible)

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Sort

    Ok, so here is a rewrite with a change in logic. The original logic was a straight deal off the top of the deck, distributing the players in the order they came off the stack. The new logic is to deal off the top and bottom of the deck paring the lowest scoring player with the highest scoring player, second lowest with second highest, etc.
    Attached Files Attached Files

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,016

    Re: Sort

    Thanks for the Add Rep.

  8. #8
    Registered User
    Join Date
    12-18-2012
    Location
    Here
    MS-Off Ver
    2016
    Posts
    10

    Re: Sort

    This is great! I ran a few simulations and the team averages were always very close. Nice!

    The only issue I ran into so far is if I change the # of teams. For example, try the same table but with 4 teams (12 players). It ends up with two teams of 4 and two teams of 2.

    If I tried 15 players, 4 teams it distributed players perfectly. However, 15 players, 5 teams did not work. I'm guessing due to the pairing.

    I tried to look at the code, but it's above my head Is there a way to adjust this to compensate? Thanks in advance again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 04-16-2015, 06:29 PM
  2. Replies: 1
    Last Post: 03-04-2015, 02:57 PM
  3. [SOLVED] I have a sort macro. How to add script to preselect rows to sort based on column value?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2014, 02:25 AM
  4. Replies: 2
    Last Post: 01-15-2014, 09:31 AM
  5. [SOLVED] Query Multiple Web Pages> Sort For Specific Criteria > Save Lists of Sort in txt files
    By Tlandress in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-15-2013, 12:09 AM
  6. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  7. Pls. reply Sort Data and copy to next coulmn when sort order chang
    By shital shah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2005, 10:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1