Hi
Another option, using vba.
This should work with any number of sets, each with any number of elements.
Write the sets in contiguous columns, starting in column A. Write each set in contiguous rows starting in row 1. Leave the column after the last set empty.
Try:
Code:
Sub Perm()
Dim rSets As Range, rOut As Range
Dim vArr As Variant, lrow As Long
Set rSets = Range("A1").CurrentRegion
ReDim vArr(1 To rSets.Columns.Count)
Set rOut = Cells(1, rSets.Columns.Count + 2)
Perm1 rSets, vArr, rOut, 1, lrow
End Sub
Sub Perm1(rSets As Range, ByVal vArr As Variant, rOut As Range, ByVal lSetN As Long, lrow As Long)
Dim j As Long
For j = 1 To rSets.Rows.Count
If rSets(j, lSetN) = "" Then Exit Sub
vArr(lSetN) = rSets(j, lSetN)
If lSetN = rSets.Columns.Count Then
lrow = lrow + 1
rOut(lrow).Resize(1, rSets.Columns.Count).Value = vArr
Else
Perm1 rSets, vArr, rOut, lSetN + 1, lrow
End If
Next j
End Sub
Ex:
[TABLE="width: 2"]
<tbody>[TR]
[TH][/TH]
[TH="width: 30, align: center"]A[/TH]
[TH="width: 30, align: center"]B[/TH]
[TH="width: 30, align: center"]C[/TH]
[TH="width: 30, align: center"]D[/TH]
[TH="width: 30, align: center"]E[/TH]
[TH="width: 30, align: center"]F[/TH]
[TH="width: 30, align: center"]G[/TH]
[TH="width: 30, align: center"]H[/TH]
[TH="width: 30, align: center"]I[/TH]
[TH="width: 30, align: center"]J[/TH]
[/TR]
[TR]
[TD="align: center"]
1[/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
2[/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
4[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
5[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
6[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
7[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
8[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
9[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
10[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
11[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
12[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
13[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
14[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
15[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
16[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
17[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a1[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
19[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
20[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
21[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
22[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
23[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
24[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b1[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
25[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
26[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
27[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
28[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
29[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
30[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b2[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
31[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
32[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c1[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
33[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
34[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c2[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
35[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d1[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
36[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]a2[/TD]
[TD="align: center"]b3[/TD]
[TD="align: center"]c3[/TD]
[TD="align: center"]d2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]
37[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="colspan: 11"] [Book1]Sheet1[/TD]
[/TR]
</tbody>[/TABLE]