3-pair Permutation / Combinations from a single list of seven (7) inputs

fastwriter

New Member
Joined
Jul 20, 2022
Messages
4
Hey gang!

Hope you are all well!

So I've been scouring the 'net for this answer and can't quite find the *exact* formula for this. Hoping I can solve this in Excel w/out VBA. The simpler, the better.

I am trying to generate a permutation list of 2-char pairs and generate a non-repeating list of three (3) combinations from the following:

- Sa
- Ur
- No
- Ma
- Ha
- Ju
- Mo

From the above list, I'd like to get a combination with only 3 of the above at time, with no repeats.

Example:
- Sa Ur No
- Sa Ur Ma
- Sa Ur Ha
- Sa Ur Ju
- Sa Ur Mo


-- Is there a simple way to do this in Excel?

Looking forward to your responses!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi & welcome to MrExcel.

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’)
 
Upvote 0
A way using VBA.

BookII.xlsm
ABCDE
1SaMoSaUr
2UrMoSaNo
3NoMoSaHa
4MaMoSaJu
5HaMoSaMa
6Ju
7Mo
Sheet13


VBA Code:
Sub Main()
Dim r As Range:         Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant:    AR = PX(r)

Set r = Range("C1")
r.Resize(UBound(AR), UBound(AR, 2)).Value2 = AR
End Sub

Function PX(r As Range)
Dim AR() As Variant:        AR = r.Value2
Dim RES() As Variant:       ReDim RES(1 To UBound(AR) - 2, 1 To 3)

MIX AR

For i = 3 To UBound(AR)
    RES(i - 2, 1) = AR(1, 1)
    RES(i - 2, 2) = AR(2, 1)
    RES(i - 2, 3) = AR(i, 1)
Next i

PX = RES
End Function

Function MIX(AR As Variant)
Dim UB As Integer:  UB = UBound(AR)
Dim RI As Integer

For i = 1 To UB
    RI = Int((UB) * Rnd() + 1)
    tmp = AR(RI, 1)
    AR(RI, 1) = AR(i, 1)
    AR(i, 1) = tmp
Next i
End Function
 
Upvote 0
Or, if you have O365...

BookII.xlsm
ABCDE
1SaJuMoSa
2UrJuMoNo
3NoJuMoUr
4MaJuMoMa
5HaJuMoHa
6Ju
7Mo
Sheet13
Cell Formulas
RangeFormula
C1:E5C1=LET(r,A1:A7,c,COUNTA(r),sb,SORTBY(SEQUENCE(c),RANDARRAY(c)),fi,INDEX(sb,1),se,INDEX(sb,2),INDEX(r,MAKEARRAY(c-2,3,LAMBDA(r,c,CHOOSE(c,fi,se,INDEX(FILTER(sb,(sb<>fi)*(sb<>se)),r))))))
Dynamic array formulas.
 
Upvote 0
Another option for 365
Fluff.xlsm
ABCDE
1Sa
2UrUrJuMo
3NoUrJuHa
4MaUrJuNo
5HaUrJuMa
6JuUrJuSa
7Mo
Data
Cell Formulas
RangeFormula
C2:E6C2=LET(a,SORTBY(A1:A7,RANDARRAY(7)),b,MAKEARRAY(5,3,LAMBDA(r,c,IF(c=3,r+c-1,c))),INDEX(a,b))
Dynamic array formulas.
 
Upvote 0
I might be looking at this a completely different way, but here's a way to generate all 3 item combinations from a list of 7 with no repeats. This doesn't require Excel 365 or VBA.

Cell Formulas
RangeFormula
C2C2=A1
D2D2=A2
E2E2=A3
C3:C38C3=IFERROR(IF(E2<>$A$7,C2,IF(D2<>$A$6,C2,IF(C2<>$A$5,INDEX($A$1:$A$7,MATCH(C2,$A$1:$A$7,0)+1),""))),"")
D3:D38D3=IFERROR(IF(E2<>$A$7,D2,IF(D2<>A$6,INDEX($A$1:$A$7,MATCH(D2,$A$1:$A$7,0)+1),IF(C2<>$A$5,INDEX($A$1:$A$7,MATCH(C2,$A$1:$A$7,0)+2),""))),"")
E3:E38E3=IFERROR(IF(E2<>$A$7,INDEX($A$1:$A$7,MATCH(E2,$A$1:$A$7,0)+1),IF(D2<>$A$6,INDEX($A$1:$A$7,MATCH(D2,$A$1:$A$7,0)+2),IF(C2<>$A$5,INDEX($A$1:$A$7,MATCH(C2,$A$1:$A$7,0)+3),""))),"")
 
Upvote 0
Solution
Thank you all for your responses.
Again, I was looking for a solution without relying upon VBA.

@Eric W - Yes, this seems to work. Thank you!
@Fluff - Thx - I'll be sure to update my details.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top