Factorials

bigmacfann

New Member
Joined
Aug 26, 2005
Messages
44
Simply stated, I need a macro that will output all the combinations of 9!/5! There will be 3024 combinations. I don't want a non-repeating combination (like 9C5=126) or a repeating permutation (like 9P5=15120). Can anyone help me here? Thank you in advance.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
For instance, the first combination would be '1 1 1 1 1' the second would be '1 1 1 1 2' the third would be '1 1 1 1 3' etc. I would like the output to be displayed where each number would have it's own cell so for instance, output number one would be A1=1, B1=1, C1=1, D1=1, E1=1. Second output would be A2=1, B2=1, C2=1, D2=1, E2=2 and so on.
 
Upvote 0
What you asked for is something like this.
Any more nested loops and it should be made recursive.
Your terms of Combinations and premutations seem correct
so the list you are asking for will be the large premutations one I think.
Switch off screen updating befor and back on after will speed it up a bit.

The confusion is what you are after.


Code:
Private Sub CommandButton1_Click()
    outrow = 0
    For x1 = 1 To 9
        For x2 = 1 To 9
            For x3 = 1 To 9
                For x4 = 1 To 9
                    For x5 = 1 To 9
                        outrow = outrow + 1
                        Cells(outrow, 1) = x1
                        Cells(outrow, 2) = x2
                        Cells(outrow, 3) = x3
                        Cells(outrow, 4) = x4
                        Cells(outrow, 5) = x5
                    Next x5
                Next x4
            Next x3
        Next x2
    Next x1

End Sub
 
Upvote 0
Or maybe it was this that you needed

Code:
Private Sub CommandButton1_Click()
    outrow = 0
    For x1 = 1 To 9
        For x2 = x1 To 9
            For x3 = x2 To 9
                For x4 = x3 To 9
                    For x5 = x4 To 9
                        outrow = outrow + 1
                        Cells(outrow, 1) = x1
                        Cells(outrow, 2) = x2
                        Cells(outrow, 3) = x3
                        Cells(outrow, 4) = x4
                        Cells(outrow, 5) = x5
                    Next x5
                Next x4
            Next x3
        Next x2
    Next x1

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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