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 ?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
sure.
24 formulas like this will do the job
=MID(A1,1,1) & MID(A1,2,1) & MID(A1,3,1) & MID(A1,4,1)
=MID(A1,1,1) & MID(A1,2,1) & MID(A1,4,1) & MID(A1,3,1)
=MID(A1,1,1) & MID(A1,3,1) & MID(A1,2,1) & MID(A1,4,1)
=MID(A1,1,1) & MID(A1,3,1) & MID(A1,4,1) & MID(A1,2,1)
=MID(A1,1,1) & MID(A1,4,1) & MID(A1,2,1) & MID(A1,3,1)
=MID(A1,1,1) & MID(A1,4,1) & MID(A1,3,1) & MID(A1,2,1)
...

Its common that lists like this aren't needed and analysis is easier than listing.
What is the goal?
 
Upvote 0
sure.
24 formulas like this will do the job
=MID(A1,1,1) & MID(A1,2,1) & MID(A1,3,1) & MID(A1,4,1)
=MID(A1,1,1) & MID(A1,2,1) & MID(A1,4,1) & MID(A1,3,1)
=MID(A1,1,1) & MID(A1,3,1) & MID(A1,2,1) & MID(A1,4,1)
=MID(A1,1,1) & MID(A1,3,1) & MID(A1,4,1) & MID(A1,2,1)
=MID(A1,1,1) & MID(A1,4,1) & MID(A1,2,1) & MID(A1,3,1)
=MID(A1,1,1) & MID(A1,4,1) & MID(A1,3,1) & MID(A1,2,1)
...

Its common that lists like this aren't needed and analysis is easier than listing.
What is the goal?


This code isn't effective

I want to extend the permutation to 6 digits numbers
 
Upvote 0
Overflow message still appear
Overflow will occur if numeric variables are declared to the wrong magnitude.

Go though the code and wherever
Code:
Dim xxx as Integer
occurs, change to
Code:
Dim xxx as Long
and if that still gives Overflow then change to
Code:
Dim xxx as Double
Here xxx just denotes any declared numeric variable.
 
Upvote 0
Anyone can help me to generate permutations for 4 digits number without repetition ?
OK. Here's a code of a type basically designed for something else, but run it as it stands and see if it's the sort of thing ...
Code:
Sub permutingsortofstuff()
Dim b(10 ^ 4) As Boolean, c() As Boolean
Dim u(1 To 10 ^ 3, 1 To 1)
Dim i&, g&, h&, q&
Randomize

For i = 1 To 10 ^ 4
g = 0: q = 0
ReDim c(9)
Do
x = Int(Rnd * 4 + 1)
If c(x) = False Then
    g = g + 1
    q = q & x
    c(x) = True
End If
Loop Until g = 4

If b(q) = False Then
    h = h + 1
    u(h, 1) = q
    b(q) = True
End If
Next i

Range("D1").Resize(h) = u
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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