Create all possible combinations

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I want VBA the could create all possible combinations using 5 groups which Min Sum is = 0 And Max Sum is =14

My 1st group contain 3 numbers in cells B2:B4 0, 1 & 2. And the rest 4 contain 0, 1, 2 & 3 in cells C2:F5

Below is the example sheet I don't how much combination could be all together only I can say in row 8 1st is with sum = 0 like 0, 0, 0, 0, 0 And last could be the sum = 14 like 2, 3, 3, 3, 3

Example sheet...


Book1
ABCDEFGH
1Group1Group2Group3Group4Group5
200000
311111
422222
53333
6
7GenerateSet1Set2Set3Set4Set5Sum
81000000
92000011
103000101
114001001
125010001
136100001
14??0
15??0
16??0
17??0
18??0
19??0
20??0
21??0
22??2333314
23
24
25
26
27
28
29
30
31
32
33
Create All Combination


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi, I am not sure may be it is permutation "not the combinations" what a am looking for....

Regards,
Kishan
 
Upvote 0
Hi, I am not sure may be it is permutation "not the combinations" what a am looking for....

Regards,
Kishan
Hi, searched in forum and goggle too. But can't find and VBA solution but find it could be "permutation with repetitions"

Regards,
Kishan
 
Last edited:
Upvote 0
[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][td="bgcolor:#C0C0C0"]
G​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td]B2: =MOD(INT(4*(ROWS($F$2:Me) - 1) / 4 ^ COLUMNS($F$2:Me)), 4)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
16​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
17​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
0​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[/table]


Copy down through row 1024.
 
Upvote 0
I am trying to figure out how you would do this in VBA using recursion, and I can't figure it out. Does anyone know how you would do that?
 
Upvote 0
In B2, replace Me with B2.
Hi shg, now it is giving results as request

Thank you very much for solving my query.

Have a nice day ahead

Regards,
Kishan :)

 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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