Gruppe
Allgemein
Problem
Wie kann ich die einzelnen Kombinationsmöglichkeiten auflisten, die ich mit der Excel-Funktion KOMBINATIONEN() bei 4 Elementen ermittle?
StandardModule: Modul1
Sub GetKombi()
Dim vCount As Variant
Dim a As Integer, b As Integer, c As Integer
Dim d As Integer, n As Integer, m As Integer
Dim s As String, sTxt As String
Columns("C:F").ClearContents
vCount = Application.InputBox( _
prompt:="Bitte Anzahl der Elemente angeben:", _
Type:=1)
If vCount = "" Then Exit Sub
vCount = CInt(vCount)
s = "A"
m = 2
Range("A2").Value = WorksheetFunction.Combin(vCount, 4)
For a = 1 To vCount - 3
For b = 2 To vCount - 2
For c = 3 To vCount - 1
For d = 4 To vCount - (c - 3) - (b - 2) - (a - 1)
If n >= Cells.Rows.Count Then
m = m + 1
n = 1
Else
n = n + 1
End If
sTxt = s & a
sTxt = sTxt & "*" & s
sTxt = sTxt & b + (a - 1)
sTxt = sTxt & "*" & s
sTxt = sTxt & c + ((b - 2) + (a - 1))
sTxt = sTxt & "*" & s
sTxt = sTxt & d + ((c - 3) + (b - 2) + (a - 1))
Cells(n, m) = sTxt
Next d
Next c
Next b
Next a
End Sub