Maximum points generator chart

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
787
I manage a team that has a handicapped players skill level. There are 8 players on the team and we can play a maximum of 5 per week.
There is a target maximum combined skill level of 2375, if we exceed that we give up points.

Our players skill levels change sometimes weekly based on prior weeks performance so I always need to recalculate this.
I have tried to create a spreadsheet where i can type in the 8 players individual skill levels and have it show me all the possible combinations that will keep me un der the 2375 limit.
I can't do it.
Would someone be willing to take a crack at this for me?

Skill levels range form 100 to 900.

Thank you all.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This might be possible with just formulas, but I found it much easier to write a macro.

Open a new workbook. Enter the names, skill levels and cap as follows:

Book2
ABCD
1PlayerLevelMax
2A1002375
3B250
4C888
5D450
6E300
7F200
8G750
9H695
10
Sheet2


Now press Alt-F11 to open the VBA editor. Press Alt-IM to Insert a Module. Then paste this code in the window that opens:

VBA Code:
Public Teams As Variant

Sub GetTeams()
Dim Players As Variant, Cap As Long

    Set Teams = CreateObject("Scripting.Dictionary")
    
    Players = Range("A2:B9").Value
    Cap = Range("D2").Value
    
    Call Recur(Players, Cap, 0, 0, 0, "")
    
    Range("F:G").ClearContents
    Range("F1:G1").Value = Array("Total", "Roster")
    Range("F2").Resize(Teams.Count).Value = WorksheetFunction.Transpose(Teams.items)
    Range("G2").Resize(Teams.Count).Value = WorksheetFunction.Transpose(Teams.keys)
    
    
End Sub

Sub Recur(ByRef Players, ByRef Cap, ByVal level As Long, ByVal nextix As Long, ByVal tot As Long, ByVal roster As String)
Dim i As Long

    If tot > Cap Then Exit Sub
    
    If level = 5 Then
        Teams.Add Mid(roster, 2), tot
        Exit Sub
    End If
    
    For i = nextix + 1 To 8
        Call Recur(Players, Cap, level + 1, i, tot + Players(i, 2), roster & "," & Players(i, 1))
    Next i
        
    
End Sub

Press Alt-Q to close the VBA editor. Back in Excel press Alt-F8 to open the macro selector. Select GetTeams and click Run. You should end up with this:

Book2
ABCDEFG
1PlayerLevelMaxTotalRoster
2A10023751988A,B,C,D,E
3B2501888A,B,C,D,F
4C8881738A,B,C,E,F
5D4502288A,B,C,E,G
6E3002233A,B,C,E,H
7F2002188A,B,C,F,G
8G7502133A,B,C,F,H
9H6951300A,B,D,E,F
101850A,B,D,E,G
111795A,B,D,E,H
121750A,B,D,F,G
131695A,B,D,F,H
142245A,B,D,G,H
151600A,B,E,F,G
161545A,B,E,F,H
172095A,B,E,G,H
181995A,B,F,G,H
191938A,C,D,E,F
202333A,C,D,F,H
212238A,C,E,F,G
222183A,C,E,F,H
231800A,D,E,F,G
241745A,D,E,F,H
252295A,D,E,G,H
262195A,D,F,G,H
272045A,E,F,G,H
282088B,C,D,E,F
292333B,C,E,F,H
301950B,D,E,F,G
311895B,D,E,F,H
322345B,D,F,G,H
332195B,E,F,G,H
34
Sheet2


Let us know how this works for you.
 
Upvote 0
I think @Eric W has provided you with an excellent solution, but just to give you an option, here's a formula approach. Adjust the handicap skill levels in B2:B9, then you can use an Autofilter on Row 12, filtering column F to <2375. You will then get a list of all combinations that fall under that value.
(Filtered version shown)
COMBINATION PERMUTATION3.xls
ABCDEF
1PlayersH/Cap
21358
32608
43504
54852
65448
76408
87472
98233
10
11
12HDR1HDR2HDR3HDR4HDR5Total
17123562326
19123582151
20123672350
21123682111
22123782175
29125672294
30125682055
31125782119
32126782079
37134682355
39135672190
40135681951
41135782015
42136781975
44145682299
45145782363
46146782323
47156781919
55235682201
56235782265
57236782225
62256782169
67356782065
69
Sheet2
Cell Formulas
RangeFormula
F17,F19:F22,F29:F32,F37,F39:F42,F44:F47,F55:F57,F62,F67F17=SUM(SUMIFS($B$2:$B$9,$A$2:$A$9,A17:E17))
 
Upvote 0
Here's the unfiltered version of the sheet:
player handicaps.xlsx
ABCDEF
1PlayersH/Cap
21358
32608
43504
54852
65448
76408
87472
98233
10
11
12HDR1HDR2HDR3HDR4HDR5Total
13123452770
14123462730
15123472794
16123482555
17123562326
18123572390
19123582151
20123672350
21123682111
22123782175
23124562674
24124572738
25124582499
26124672698
27124682459
28124782523
29125672294
30125682055
31125782119
32126782079
33134562570
34134572634
35134582395
36134672594
37134682355
38134782419
39135672190
40135681951
41135782015
42136781975
43145672538
44145682299
45145782363
46146782323
47156781919
48234562820
49234572884
50234582645
51234672844
52234682605
53234782669
54235672440
55235682201
56235782265
57236782225
58245672788
59245682549
60245782613
61246782573
62256782169
63345672684
64345682445
65345782509
66346782469
67356782065
68456782413
69
Sheet2
Cell Formulas
RangeFormula
F13:F68F13=SUM(SUMIFS($B$2:$B$9,$A$2:$A$9,A13:E13))
 
Upvote 0
Eric - Great approach, did not think of a macro. Works great. tks

Kevin, thanks for your solution also, sadly i could not get it to run not sure what cellos to place the formula into nor what all the hrd1 thru hrd5 headers are for.
 
Upvote 0
Eric,
Just found one issue with this macro. My fault when I said there were 8 players on the roster, that is MAX players allowed.
Some teams have only 6 or seven.
When I reduce the # of players I get inaccurate results, that is to say it displays counts of 4 ppl or less. It always has to be 5.
Can you adjust for that?


playerlevelTotalRoster
1​
100​
1969​
1,2,3,4,5
2​
250​
2004​
1,2,3,4,6
3​
850​
2067​
1,2,3,4,7
4​
357​
1557​
1,2,3,4,
5​
412​
2059​
1,2,3,5,6
6​
447​
2122​
1,2,3,5,7
7​
510​
1612​
1,2,3,5,
2157​
1,2,3,6,7
1647​
1,2,3,6,
1710​
1,2,3,7,
 
Upvote 0
Sure, try this:

Rich (BB code):
Public Teams As Variant

Sub GetTeams()
Dim Players As Variant, Cap As Long

    Set Teams = CreateObject("Scripting.Dictionary")
    
    Players = Range("A2:B" & Range("A2").End(xlDown).Row).Value
    Cap = Range("D2").Value
    
    Call Recur(Players, Cap, 0, 0, 0, "")
    
    Range("F:G").ClearContents
    Range("F1:G1").Value = Array("Total", "Roster")
    Range("F2").Resize(Teams.Count).Value = WorksheetFunction.Transpose(Teams.items)
    Range("G2").Resize(Teams.Count).Value = WorksheetFunction.Transpose(Teams.keys)
    
End Sub

Sub Recur(ByRef Players, ByRef Cap, ByVal level As Long, ByVal nextix As Long, ByVal tot As Long, ByVal roster As String)
Dim i As Long

    If tot > Cap Then Exit Sub
    
    If level = 5 Then
        Teams.Add Mid(roster, 2), tot
        Exit Sub
    End If
    
    For i = nextix + 1 To UBound(Players)
        Call Recur(Players, Cap, level + 1, i, tot + Players(i, 2), roster & "," & Players(i, 1))
    Next i
        
End Sub

I only had to change 2 lines. It now looks for the bottom row. Make sure there are no gaps in the list, and that the rows following the names are empty.
 
Upvote 0
Eric,
Thank you for what you've done so far.
I had an illness in the family and had to quit for a bit.
Getting back yo this now and am still getting an error.

here is the sample data I'm using. The macro errors out on line "Range("F2").Resize(Teams.Count).Value = WorksheetFunction.Transpose(Teams.Items)"
Playerskill
edward
514​
larry
458​
britney
342​
doug
424​
skip
539​
brendan
503​
jerry
459​
john
469​
 
Upvote 0
I'm sorry to hear about your family's illness. I hope things are better.

As far as the macro, did you put the cap in cell D2? If not, that would cause the error you're seeing.
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,711
Members
449,118
Latest member
MichealRed

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