Can someone give the VB code for a macro to get all possible combinations of n items taking r items from it at a time? I am looking for the code to list all the nCr combinations
How's this? Note that there is a limit as to how big a number you can calculate...
[pre]
Code:
Function Combos(n As Integer, r As Integer) As Double
If n < 1 Or r < 1 Then
Combos = 0
Exit Function
End If
Combos = 1
For i = 1 To r
'In Case n is less than r
Do While n > 0
Combos = Combos * n
n = n - 1
Loop
Next
End Function