Permute values in one column

thundaraga

New Member
Joined
Feb 8, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a list of values in column A such as

A
B
C
D
E

I want to output the list of permutations in column B for 2, 3 and 4 ways.:

A. B
B. A
A, B, C
A, C, B
B, A, C
A, B, C, D
A, C, B, D
B, A, C, D
E, A, C, D

Does anyone have any idea how it could be done in VBA?

Thank you!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Here is a non-VBA solution. It might have been welded into one long nasty formula, but it gets too complex. LET might make quick work of it, but I don't have LET.

MrExcelPlayground6.xlsx
ABCDEFGHIJKLMNO
1RESULT
2 000000000 A0AAA
3A100010001AB0BAC
4B200020002BC0CAD
5C300030003CD0DAE
6D400040004DE0EBA
7E500050005EA0ABB
8600100010AAA0AABD
9700110011AAAB1ACBE
10800120012ABAC0ADCA
11900130013ACAD0AECB
121000140014ADAE0BCC
131100150015AEB0BACE
141200200020BBA0BBDA
151300210021BABB0BDDB
161400220022BBBC1BEDC
171500230023BCBD0CDD
181600240024BDBE0CAEA
191700250025BEC0CBEB
201800300030CCA0CCEC
211900310031CACB0CEED
222000320032CBCC0DEE
232100330033CCCD1DAABA
242200340034CDCE0DBABD
252300350035CED0DCABE
262400400040DDA0DDACA
272500410041DADB0EACC
282600420042DBDC0EAACE
292700430043DCDD0EBADA
302800440044DDDE1ECADC
312900450045DEE0EDADD
323000500050EEA0EEAEA
333100510051EAEB0AAAEC
343200520052EBEC0ACAED
Sheet28
Cell Formulas
RangeFormula
A2A2=""
B2:B7777B2=SEQUENCE(6^5,1,0)
C2:C7777C2=BASE(B2#,6,4)
D2:G7777D2=MID(C2#,{1,2,3,4},1)
H2:K7777H2=INDEX(A2:A7,D2#+1)
L2:L7777L2=INDEX(H2#,ROW(B2#),1)&INDEX(H2#,ROW(B2#),2)&INDEX(H2#,ROW(B2#),3)&INDEX(H2#,ROW(B2#),4)
M2:M7777M2=(LEN(C2#)-LEN(SUBSTITUTE(C2#,1,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,2,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,3,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,4,""))>1)++(LEN(C2#)-LEN(SUBSTITUTE(C2#,5,""))>1)
N2:N1547N2=FILTER(L2#,M2#=0,"")
O2:O346O2=UNIQUE(FILTER(N2#,(LEN(N2#)>1),""))
Dynamic array formulas.
 
Upvote 0
Here is a non-VBA solution. It might have been welded into one long nasty formula, but it gets too complex. LET might make quick work of it, but I don't have LET.

MrExcelPlayground6.xlsx
ABCDEFGHIJKLMNO
1RESULT
2 000000000 A0AAA
3A100010001AB0BAC
4B200020002BC0CAD
5C300030003CD0DAE
6D400040004DE0EBA
7E500050005EA0ABB
8600100010AAA0AABD
9700110011AAAB1ACBE
10800120012ABAC0ADCA
11900130013ACAD0AECB
121000140014ADAE0BCC
131100150015AEB0BACE
141200200020BBA0BBDA
151300210021BABB0BDDB
161400220022BBBC1BEDC
171500230023BCBD0CDD
181600240024BDBE0CAEA
191700250025BEC0CBEB
201800300030CCA0CCEC
211900310031CACB0CEED
222000320032CBCC0DEE
232100330033CCCD1DAABA
242200340034CDCE0DBABD
252300350035CED0DCABE
262400400040DDA0DDACA
272500410041DADB0EACC
282600420042DBDC0EAACE
292700430043DCDD0EBADA
302800440044DDDE1ECADC
312900450045DEE0EDADD
323000500050EEA0EEAEA
333100510051EAEB0AAAEC
343200520052EBEC0ACAED
Sheet28
Cell Formulas
RangeFormula
A2A2=""
B2:B7777B2=SEQUENCE(6^5,1,0)
C2:C7777C2=BASE(B2#,6,4)
D2:G7777D2=MID(C2#,{1,2,3,4},1)
H2:K7777H2=INDEX(A2:A7,D2#+1)
L2:L7777L2=INDEX(H2#,ROW(B2#),1)&INDEX(H2#,ROW(B2#),2)&INDEX(H2#,ROW(B2#),3)&INDEX(H2#,ROW(B2#),4)
M2:M7777M2=(LEN(C2#)-LEN(SUBSTITUTE(C2#,1,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,2,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,3,""))>1)+(LEN(C2#)-LEN(SUBSTITUTE(C2#,4,""))>1)++(LEN(C2#)-LEN(SUBSTITUTE(C2#,5,""))>1)
N2:N1547N2=FILTER(L2#,M2#=0,"")
O2:O346O2=UNIQUE(FILTER(N2#,(LEN(N2#)>1),""))
Dynamic array formulas.
Wow fantastic thanks! Just wondering if I want to have a comma added between each value i.e. (A,B,C,D) instead of (ABCD), how could i go about changing it?
 
Upvote 0
hmm i realised it starts repeating the permutations after a certain number of rows and it is limited to 5 values in Column A. If there are more than 5 values in column A, then the permutation result would not show them.
 
Upvote 0
To use more than 5, change the formula in B2 to =sequence((number of different letters+1)^(max number of characters in the output+1). In H2, change the index range from A2:A7 to A2:A??.

I don't think it repeats as much as it isn't sorted in the way you would expect. Nothing is there twice in Column O.

Commas are tricky while trying to maintain the live arrays... Put this in L2:
Excel Formula:
=SUBSTITUTE(TRIM(INDEX(H2#,ROW(B2#),1)&" "&INDEX(H2#,ROW(B2#),2)&" "&INDEX(H2#,ROW(B2#),3)&" "&INDEX(H2#,ROW(B2#),4))," ",", ")
 
Upvote 0
To use more than 5, change the formula in B2 to =sequence((number of different letters+1)^(max number of characters in the output+1). In H2, change the index range from A2:A7 to A2:A??.

I don't think it repeats as much as it isn't sorted in the way you would expect. Nothing is there twice in Column O.

Commas are tricky while trying to maintain the live arrays... Put this in L2:
Excel Formula:
=SUBSTITUTE(TRIM(INDEX(H2#,ROW(B2#),1)&" "&INDEX(H2#,ROW(B2#),2)&" "&INDEX(H2#,ROW(B2#),3)&" "&INDEX(H2#,ROW(B2#),4))," ",", ")
Hmm the result still shows the permutation of 5 letters. Do i also need to change the formula in cell C2?
 
Upvote 0
You are right. Change the BASE formula:

=BASE(B2#,{number of different items +1},{max number in a set})
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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