Public result() As Variant
Function Combinations(rng As Range, n As Single)
rng1 = rng.Value
ReDim result(n - 1, 0)
Call Recursive(rng1, n, 1, 0)
ReDim Preserve result(UBound(result, 1), UBound(result, 2) - 1)
Combinations = Application.Transpose(result)
End Function
Function Recursive(r As Variant, c As Single, d As Single, e As Single)
Dim f As Single
For f = d To UBound(r, 1)
result(e, UBound(result, 2)) = r(f, 1)
If e = (c - 1) Then
ReDim Preserve result(UBound(result, 1), UBound(result, 2) + 1)
For g = 0 To UBound(result, 1)
result(g, UBound(result, 2)) = result(g, UBound(result, 2) - 1)
Next g
Else
Call Recursive(r, c, f + 1, e + 1)
End If
Next f
End Function
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
3 | Thee | Thee | Pluto | Iruma | ||
4 | Pluto | Thee | Pluto | **** | ||
5 | Iruma | Thee | Pluto | Elite. | ||
6 | **** | Thee | Iruma | **** | ||
7 | Elite. | Thee | Iruma | Elite. | ||
8 | Thee | **** | Elite. | |||
9 | Pluto | Iruma | **** | |||
10 | Pluto | Iruma | Elite. | |||
11 | Pluto | **** | Elite. | |||
12 | Iruma | **** | Elite. | |||
Sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B3:D12 | B3 | =Combinations(A3:A7,3) |
Dynamic array formulas. |
Is it what you were looking for?
What version of Excel are you using?
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
When using something other than Excel you need to post in the General Discussion & Other Applications section of the board & make it clear what you are using. I have done that for you this time.