Team Roster Ratings

HomePro

Board Regular
Joined
Aug 3, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I need help. Cant figure this out.
I have 8 people on a team, each with an assigned skill level from 100-900.
I would like to produce a table to show all possible combinations of five players where the combined skill level does not exceed 2375 without repeating players.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
What do you mean by no repeating player?
Within a combination (of course)?
Or, will all combinations include unique players compared to others? Then only one combination will be possible??
 
Upvote 0
With the setup below:
1670073299635.png

VBA Code:
Dim comboMatrix() As Variant
Dim count As Long
Sub teamSort()
  Dim players() As Variant
  Dim points() As Variant
  Dim numComb As Long
  Dim lRow As Integer, totalPoints As Integer, limitPoint As Integer, c As Integer
 
  limitPoint = 2375 'Limit point
  numComb = 5 'Length of combinations
  lRow = Cells(Rows.count, 1).End(xlUp).Row
 
 
  ReDim players(lRow)
  ReDim points(lRow)
  For i = 1 To lRow
    players(i) = Cells(i, 1).Value
    points(i) = Cells(i, 2).Value
  Next
 
  Call CombosNoRep(players, numComb)
 
  c = 4
  For i = 1 To count - 1
    totalPoints = 0
    For j = 1 To numComb
      For k = 1 To lRow
       If players(k) = comboMatrix(i, j) Then
         totalPoints = totalPoints + points(k)
       End If
      Next
    Next
    If totalPoints <= limitPoint Then
      For r = 1 To numComb
        Cells(r, c).Value = comboMatrix(i, r)
        Cells(r, c + 1).Value = points(r)
      Next
      Cells(r, c ).Value = "TOTAL" 'Delete this line if you don't want to see the totals.
      Cells(r, c + 1).Value = totalPoints 'Delete this line if you don't want to see the totals.
      c = c + 3
    End If
  Next
End Sub
Sub CombosNoRep(ByRef v() As Variant, r As Long)
Dim i As Long, k As Long, z() As Variant
Dim numRows As Long, numIter As Long, n As Long

    count = 1
    n = UBound(v)
    numRows = nChooseK(n, r)

    ReDim z(1 To r)
    ReDim comboMatrix(1 To numRows, 1 To r)
    For i = 1 To r: z(i) = i: Next i

    Do While (count <= numRows)
        numIter = n - z(r) + 1
        For i = 1 To numIter
            For k = 1 To r: comboMatrix(count, k) = v(z(k)): Next k
            count = count + 1
            z(r) = z(r) + 1
        Next i

        For i = r - 1 To 1 Step -1
            If Not (z(i) = (n - r + i)) Then
                z(i) = z(i) + 1
                For k = (i + 1) To r: z(k) = z(k - 1) + 1: Next k
                Exit For
            End If
        Next i
    Loop
End Sub
Function nChooseK(n As Long, k As Long) As Long
Dim temp As Double, i As Long
    temp = 1
    For i = 1 To k: temp = temp * (n - k + i) / i: Next i
    nChooseK = CLng(temp)
End Function
Result:
1670073353889.png
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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