Vba to list all possible permutations

Gordonik

Board Regular
Joined
Jan 30, 2014
Messages
127
Based on the sample data set. I am looking for a macro to return all possible permutations with repetition (order matters).
Let this code be universal (not only 3 but cover N unique arguments in a data set)
Let's this macro to do it in a new sheet and list an output in columns.
Google shows plenty of examples for string but not ranges.
There are a couple also where custom function is used but I do not want to use any Excel formula. Just run the code and get results.

1jp2li.jpg


Someone ready for this?
 
Last edited:
Hi PGC,

I also tried the code and it is brilliant, really good stuff! But instead of "a" "b" "c" i want all the combinations of a 5 x 3 matrix eg (02 04 06 07 08 12 14 16 17 18 22 00 00 00 00) still having the permutations with repetition. Subsets of 5 as seen below.

(02 04 06 08 14)
(02 04 06 08 16)
Hello &#x2605 hicrpot10, in that case I will suggest you to use pgc01 code under this link you will find your answer sure</SPAN></SPAN>

https://www.mrexcel.com/forum/excel-questions/277924-combination-help-5.html#post1424848

Regards,</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I tested the code with a small combination with repetition and it produced the expected result.

Tag: VBA combination with repetition.
 
Upvote 0
Really great stuff, I appreciate that you shared it!
I have a question: I tried with 12 elements (which means 479million permutations), but I got run time error '7' - Out of memory. Do you have any suggestions ?
Thanks in advance
 
Upvote 0
  • Permutations can be with or without repetition, which is your case?
  • Permutations are defined by two parameters, but you informed only one (12). What is the other one?
 
Upvote 0
Hi, this is what I'm trying to permute. Obviously, I don't write them into the sheet as Excel would not able to handle that many lines, but I want to use the vPerms array which is filled with the data. But it says out of memory. Any ideas?

JD4tROC0eZQ2pokmDPW2gKFNgszyUClW-XCzdUYNzQOQdKIYuakRbp9ztf3T94NrfLyfJtdXC95vttHfjMFy7Qzz-GEVID2O3iluc_vLYHslOi0HAPCmMSjgzi0E8sD6kfonihgGQWso7mX-KfOo7fVqKzYzFnxXmQPWA2ivbC3rK_yVYPobuGYC9ZcJzC1oJ4CpZZs7_xRZXUgbBJ9ZaM7ewSRG-Fb1MIbEBE9eCEpF2UaAffBJveSGmf6WGr5tZbiD2RI634UCfYcNq56RsTsLDJvq_tKMnEH7F6Gw7AjlnxosThfNzXRViCIaBVxF_Uf1_I7qalOiSdxC-_8PkjacZSUM97C_eTXQ54IfxRO6EFEJdsgc4TRz_wVjrEV6qZc5lNuf3ZAuhPI0kbrlOwqzjzMST-yO6Rgk3oG-qaMboYOhm2yY0gGUqwQNh6KIsz_udAfCAHBvVmwi9sig9UGaG6AuL9Q3KVaX2WGDBrZJstqy_lKz7ecngnbKp3rELGKdNA0_0sK4mXoWFw181xwwTEZlSakkphBtqeO0KNjO0tn7l1pF15CO-qwNNmM2WEEYbVO2PeAlDXULJzaWkDy6FdXR65tP1Q1NLY0C_RAUWTIalyEPM6Kok8CjRotoa09VvrwqcwDhC3JiWrlzvZhM=w272-h369-no



  • Permutations can be with or without repetition, which is your case?
  • Permutations are defined by two parameters, but you informed only one (12). What is the other one?
 
Upvote 0
Hi

I am at work and the firewall is probably preventing me from seeing what you posted.
I will try to visualize it at home.
 
Upvote 0
hi, the picture contains basically:

Elements | Qty
A | 1
B | 1
C | 1
D | 1
E | 1
F | 1
G | 1
H | 1
I | 1
J | 1
K | 1
L | 1

So 12 pcs of elements, with quantities 1.



Hi

I am at work and the firewall is probably preventing me from seeing what you posted.
I will try to visualize it at home.
 
Upvote 0
Could you not examine them one by one instead of generating them all?

What are you trying to do?
 
Upvote 0

Forum statistics

Threads
1,223,992
Messages
6,175,829
Members
452,673
Latest member
LaMiaAvy

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