Sub
KombinationenOhneZuruecklegenArray(
ByVal
n
As
Integer
,
ByVal
k
As
Integer
,
ByRef
ar
As
Variant
)
Dim
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 - 1
Next
For
i = 2
To
lngSize
For
j = 1
To
k
ar(i, j) = ar(i - 1, j)
Next
arInc ar, i, n - 1, k, k
Next
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
x()
Dim
n
As
Integer
, k
As
Integer
, lngSize
As
Long
Dim
i
As
Long
, j
As
Integer
Dim
arKombis, arStrings, arHilf, arZahlen
arZahlen = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49)
n = 49
k = 6
KombinationenOhneZuruecklegenArray n, k, arKombis
lngSize = UBound(arKombis)
ReDim
arStrings(1
To
lngSize, 1
To
1)
ReDim
arHilf(1
To
k)
For
i = 1
To
lngSize
For
j = 1
To
k
arHilf(j) = arZahlen(arKombis(i, j))
Next
arStrings(i, 1) = Join(arHilf,
", "
)
Next
Range(
"A1"
).Resize(lngSize) = arStrings
End
Sub