Hallo zusammen,
ich hab ein Makro der mir aus einer bestimmten Anzahl von Zahlen (aktuell bis 32) Kombinationen erstellt. Diese erstellten Kombis trägt mir der Makro in A2 nach unten dann ein. Da Excel nicht mehr Zeilen hat, kann ich die Stückzahl der Zahlen nicht erweitern. Denn ich hätte gern mehr Zahlen verwendet (max 35). Kann mir bitte einer den Makro so umschreiben, dass wenn Excel am Ende seiner Zeilenanzahl in Spalte A ist er in Spalte B weiter schreibt.
Vielen Dank schonmal Vorab!
Option Explicit
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 ' j um ab 1 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 - 1, k, k ' arInc ar, i, n, k, k ' um ab 1 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 zweiunddreizig()
Dim n As Integer, k As Integer, lngSize As Long
Dim i As Long, j As Integer
Dim arKombis, arStrings, arHilf, arZahlen
arZahlen = Array(Cells(2, 11), Cells(2, 12), Cells(2, 13), Cells(2, 14), Cells(2, 15), Cells(2, 16), Cells(2, 17), Cells(2, 18), Cells(2, 19), Cells(2, 20), Cells(2, 21), Cells(2, 22), Cells(2, 23), Cells(2, 24), Cells(2, 25), Cells(2, 26), Cells(2, 27), Cells(2, 28), Cells(2, 29), Cells(2, 30), Cells(2, 31), Cells(2, 32), Cells(2, 33), Cells(2, 34), Cells(2, 35), Cells(2, 36), Cells(2, 37), Cells(2, 38), Cells(2, 39), Cells(2, 40), Cells(2, 41), Cells(2, 42)) ' (3, 9, 12, 14, 16, 33, 34, 35)
n = 32 ' Anzahl der Zahlen
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("A2").Resize(lngSize) = arStrings
End Sub
VG Thomas