Permutations & Goal Seek

dkubiak

Board Regular
Joined
May 17, 2004
Messages
137
Office Version
  1. 2013
Platform
  1. Windows
I have 7 different groups that I need to arrange in the most efficient order. The efficiency model is already built, and I have 7 cells where I input the order. Then, I have one cell that displays the efficiency.

Since I cannot use a group more than once, I have 5040 permutations:

7*6*5*4*3*2*1 = 5040

I would like to use "Goal Seek" to pick the most efficient permutation.

I have half of an idea:

List the 5040 permutations with an ID column (1, 2, 3...). Then, have cell where I choose the permutation I want by entering the ID. The input cells for the order then use the ID to select the appropriate group (Vlookup?)

Goal seek then uses the ID cell (where i enter the one I want) and the efficiency output.

Any thoughts on this idea?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Also, is there a permutation generator for excel?
 
Upvote 0
Here's a simple one:

Code:
Option Explicit
Dim asPerm() As Variant
Dim iRow As Long
 
Sub test()
    Const sInp      As String = "1234567"
    With WorksheetFunction
        If .Fact(Len(sInp)) > Rows.Count Then Exit Sub
        ReDim asPerm(1 To .Fact(Len(sInp)))
 
        iRow = 0
        GetPermutations "", sInp
 
        Columns(1).ClearContents
        Range("A1").Resize(UBound(asPerm)) = .Transpose(asPerm)
    End With
End Sub
 
Sub GetPermutations(sCAR As String, sCDR As String)
    Dim i           As Long
    Dim j           As Long
 
    j = Len(sCDR)
    If j Then
        For i = 1 To j
            GetPermutations sCAR & Mid(sCDR, i, 1), _
                            Left(sCDR, i - 1) & Right(sCDR, j - i)
        Next i
    Else
        iRow = iRow + 1
        asPerm(iRow) = sCAR & sCDR
    End If
End Sub

It lists the permutations to A1:A5040.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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