This will list the 5151 combinations. It uses whole numbers rather than decimals. but you can divide all the numbers by 100.
Sub testnComb()
Debug.Print nComb(3, 100)
End Sub
Function nComb(nItems As Long, nTot As Long) As Long
' Returns the number of combinations that nItems can be adjusted
' in increments of 1 such that the total is always nTot
Dim ai() As Long
Dim i As Long
Dim iSum As Long
ReDim ai(1 To nItems)
' setup to get first combination and ensure initial correct total
ai(1) = -1
ai(nItems) = nTot
iSum = nTot - 1
Do
iSum = iSum - ai(nItems)
ai(nItems) = 0
For i = 1 To nItems - 1
If iSum < nTot Then
iSum = iSum + 1
ai(i) = ai(i) + 1
Exit For
Else
iSum = iSum - ai(i)
ai(i) = 0
End If
Next i
If i > nItems - 1 Then Exit Function '-------------------------->
ai(nItems) = nTot - iSum
iSum = nTot
nComb = nComb + 1
'*******************************
Dim iRow As Long
iRow = iRow + 1
Cells(iRow, 1).Resize(, nItems).Value = ai
'*******************************
Loop
End Function
Bookmarks