Moin!
HIer nochmal lesbar:
Sub KombinationenOhneZuruecklegenArray(ByVal n As Integer, ByVal k As Integer)
Dim ar As Variant, i As Long, j As Integer, lngSize As Long
lngSize = WorksheetFunction.Combin(n, k)
ReDim ar(1 To lngSize, 1 To k)
For j = 1 To k
ar(1, j) = j ' j - 1 um ab 0 zu zählen
Next
For i = 2 To lngSize
For j = 1 To k
ar(i, j) = ar(i - 1, j)
Next
arInc ar, i, n, k, k ' arInc ar, i, n - 1, k, k ' um ab 0 zu zählen
Next
Range("A1").Resize(lngSize, k) = ar
End Sub
Sub arInc(ByRef ar As Variant, ByVal i As Long, ByVal n As Integer, ByVal k As Integer, ByVal intSpalte As Integer)
Dim intVal As Integer, j As Integer
intVal = ar(i, intSpalte)
If intVal < n - (k - intSpalte) Then
For j = intSpalte To k
intVal = intVal + 1
ar(i, j) = intVal
Next
Else
arInc ar, i, n, k, intSpalte - 1
End If
End Sub
Sub TestIt()
KombinationenOhneZuruecklegenArray 50, 5
End Sub
VG
|