Hi
Welcome to the board
With the set of elements in A1, down, try:
Code:
Sub PowerSetRept()
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 CombinationsNP(vElements, i, vresult, lRow, 1, 1)
Next i
End Sub
Sub CombinationsNP(vElements As Variant, p As Long, vresult As Variant, lRow As Long, iElement As Long, iIndex As Long)
Dim i As Long
For i = iElement To UBound(vElements)
vresult(iIndex) = vElements(i)
If iIndex = p Then
lRow = lRow + 1
Range("C" & lRow).Resize(, p) = vresult
Else
Call CombinationsNP(vElements, p, vresult, lRow, i, iIndex + 1)
End If
Next i
End Sub
[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]
[/TR]
[TR]
[TD="align: center"]
1[/TD]
[TD="align: left"]a[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
2[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
3[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]a[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]c[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]a[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
14[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
16[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]a[/TD]
[TD="align: left"]c[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]b[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]b[/TD]
[TD="align: left"]c[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
20[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: left"]c[/TD]
[TD="align: left"]c[/TD]
[TD="align: left"]c[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]
21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="colspan: 7"] [Book1]Sheet2[/TD]
[/TR]
</tbody>[/TABLE]