How to generate permutated number ?

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
If I type 1234, excel with generate & permutate 24 sets of numbers like 1234,1243,1324,1342,1423,1432, 2134,2143, 2314,2341, 2413,2431,3124,3142,3214,3241,3412,3421,4123, 4132,4213,4231,4312,4321.

Is that possible to conduct in Excel ?
 
What code have you tried to get an input box to input the values in A1:D1?

Conditional formatting can hide the #N/A errors.
 
Last edited:
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Option Explicit
Dim var As New Collection
Dim CurrentRow As Long
Sub Perm()

Dim InString As String
InString = InputBox("Enter text to permute:")
 
Upvote 0
To get rid of the #N/A and put each into its own cocatenated cell, you could alter UniquePermutations.
Code:
Function UniquePermutes(BaseArray As Variant)
    Dim Permuting As Variant
    Dim i As Long, j As Long, Pointer As Long
    Dim scoreKeeper() As String
    Dim tempArray As Variant
    
    If TypeName(BaseArray) = "Range" Then
        If BaseArray.Cells.Count = 1 Then
            BaseArray = Array(BaseArray.Value)
        ElseIf BaseArray.Rows.Count = 1 Then
            BaseArray = Application.Transpose(Application.Transpose(BaseArray.Value))
        ElseIf BaseArray.Columns.Count = 1 Then
            BaseArray = Application.Transpose(BaseArray.Value)
        Else
            UniquePermutes = CVErr(xlErrValue)
        End If
    ElseIf Not (BaseArray) Like "*()" Then
        UniquePermutes = CVErr(xlErrNum)
    End If
    
    Permuting = Permutations(UBound(BaseArray))
    ReDim scoreKeeper(1 To UBound(Permuting))
    
    tempArray = BaseArray
    For i = 1 To UBound(Permuting)
        For j = 1 To UBound(tempArray)
            tempArray(j) = BaseArray(Permuting(i)(j))
        Next j
        If IsError(Application.Match(Join(tempArray), scoreKeeper, 0)) Then
            Pointer = Pointer + 1
            scoreKeeper(Pointer) = Join(tempArray)
        End If
    Next i
    
    UniquePermutes = scoreKeeper()
 
End Function
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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