vložiť VBA kód do Excelu:
klávesová zkratka Alt+F11 --> v menu VBA: Insert --> Module --> do prázdného okna vpravo kopírujte nasledujúci kód:
Option Explicit
' PGC Jan 2014
' Calculates all possible permutations without repetition of a set
' Set in A1, down. Result in C1, down and accross. Clears C:Z.
Sub PermutationsWRAll()
Dim vElements As Variant, vresult As Variant
Dim lRow As Long, i As Long
vElements = Application.Transpose(Range("A1", Range("A1").End(xlDown)))
Columns("C:Z").Clear
lRow = 1
For i = 1 To UBound(vElements)
ReDim vresult(1 To i)
Call PermutationsWR(vElements, i, vresult, lRow, 1, 1)
Next i
End Sub
Sub PermutationsWR(vElements As Variant, p As Long, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)
Dim i As Long, j As Long
Dim b As Boolean
For i = 1 To UBound(vElements)
b = True
For j = 1 To iIndex - 1
If vresult(j) = vElements(i) Then
b = False
Exit For
End If
Next j
If b Then
vresult(iIndex) = vElements(i)
If iIndex = p Then
lRow = lRow + 1
Range("C" & lRow).Resize(, p) = vresult
Else
Call PermutationsWR(vElements, p, vresult, lRow, i + 1, iIndex + 1)
End If
End If
Next i
End Sub