+ Reply to Thread
Results 1 to 22 of 22

How do I generate all possible unique arrangements of 5 numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    How do I generate all possible unique arrangements of 5 numbers

    I am in need of advice on how to generate all the possible combinations of 5 numbers, e.g. 1,2,3,4,5. Then 2,3,4,5,1 and so on, in a series of excel columns and rows. Also for 6 numbers etc. Thanks for suggestions...John

  2. #2
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How do I generate all possible unique arrangements of 5 numbers

    Are you wanting 2 digit numbers like 35 and 53 or are you wanting 5 digit numbers?
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  3. #3
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thanks. You are right. I am after permutations. Any solution is welcome. ..

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    permutations not combinations! eg
    123 has 1 combination of 3 but 6 permutations
    123
    321
    132
    312
    213
    231

    is it always a series?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thanks ndm. I need all five numbers, with each digit in a separate cell on the same row. Then in the next row the next possible combination of numbers.

    Quote Originally Posted by jazzahanna View Post
    I am in need of advice on how to generate all the possible combinations of 5 numbers, e.g. 1,2,3,4,5. Then 2,3,4,5,1 and so on, in a series of excel columns and rows. Also for 6 numbers etc. Thanks for suggestions...John

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    this workbook does it but i dont know if it will run on mac 2011
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thanks Martin. It's throwing up an error in the macro, screenshot attached. Any fix for that?
    Attached Images Attached Images

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    no idea its probably an office 2011 thing works fine in 2007
    what did you put in it?

  9. #9
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    I was just opening the macro. Probably a mac problem. I'll check on my wife's PC tomorrow and let you know. Thanks v much.

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How do I generate all possible unique arrangements of 5 numbers

    I did this manually.

    First, I entered 11111 in A1 and selected A1. I then went to Fill, Series. Select columns, selected Columns and end value of 55555 then OK. This filled column a with all possible numbers of 5 digits that could be formed by the digits 1,2,3,4,5 and also 0,6,7,8,9

    I then used Find and one at a time found 0, selected All then deleted all numbers that had a 0. This I repeated for numbers 6, 7, 8, 9 This left me with numbers that only had the digits from 1 to 5.

    I selected column A and then the Data tab, Text to columns, Fixed width and set the delimiters between each digit. Clicked finish and this separated the numbers into 5 columns.

    I then sorted all the remaining numbers from smallest to largest. I then used the COUNTIF to count the number of 1's 2's 3's, 4's and 5's in each row. =countif($a1:$e1,1) =countif($a1:$e1,2) =countif($a1:$e1,3) =countif($a1:$e1,4) and =countif($a1:$e1,5) in the cells G1:K1 and copied down the length of the data.

    Next step was to use in L1 =sum(G1:k1) and copied down the length of the data. All data was selected and sorted on column L. All rows that didn't total 5 were deleted. This left only rows of 5 digits with the digits 1 to 5 with no duplicates. (124 rows)

    Using the above for 6 digits, I ended up with 720 6 digit combinations.

  11. #11
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thank you @ newdoverman. This is a great solution, for me, as it explains all the steps that would probably be written in a macro in order to achieve the outcome. I've enjoyed following the step by step logic!

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    slighly different manual method
    123456 in cell a1
    use series fill columns increment 1 stop value 654321

    then in b1
    =SUMPRODUCT(--ISNUMBER(SEARCH({"1","2","3","4","5","6"},A1)))=6
    double click the fill handle to fill down
    copy paste special values over the formulas to remove them
    filter on true
    copy paste visible rows to new sheet

    then text to columns fixed width on that


    alternative to copying visible rows is to sort by column b descending
    go down to first false in this case it would be a721
    click the row number to select the row then ctrl+shift+down arrow to select all the false then delete
    Last edited by martindwilson; 12-07-2013 at 11:11 PM.

  13. #13
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thanks very much @ martindwilson. I shall have a play with that as well - appreciated

  14. #14
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    i just tried the xlsm i uploaded and i get the same error must be a version thing
    try the xls version instead
    ITS LIMITED BY ROWS SO THE MOST YOU'LL GET IS 1-8
    also attached is 1-5 1-6 1-7 1-8 done also included is the same thing with text
    you can use that as a template so say you wanted
    12 35 67 89 41
    you can find replace each letter with one of those
    Attached Files Attached Files
    Last edited by martindwilson; 12-07-2013 at 11:48 PM.

  15. #15
    Forum Contributor
    Join Date
    10-21-2012
    Location
    miami, florida usa
    MS-Off Ver
    Excel 2007
    Posts
    260

    Re: How do I generate all possible unique arrangements of 5 numbers

    Hi, Mr MartinWilson and Mr Newdoverman,

    I'm sorry to say something in this post, I'm not an expert, I'm just a old man that is trying to learn excel..

    I was reading about Permutation Code that Mr martinwilson supplied to Mr Hazzahanna, and the error
    If N > Cells.Count Then GoTo DataError
    Suppossedly Is caused by the Excel version, according to various links,

    That Line have to be replaced by CountLarge something word
    If N > Cells.CountLarge Then GoTo DataError
    suppossedly the older excel just manage less than 2147483647 ( my god its a lot!)
    and the newer excel handle 17179869184 cells.

    Thank you, and I apologies if i mess a Forum rule.

    Best Regards from Miami.

    David

  16. #16
    Forum Contributor
    Join Date
    10-21-2012
    Location
    miami, florida usa
    MS-Off Ver
    Excel 2007
    Posts
    260

    Re: How do I generate all possible unique arrangements of 5 numbers

    Hi, Mr MartinWilson and Mr Newdoverman,

    Here is the link (sorry, forgot)

    http://answers.microsoft.com/en-us/o...1-522bfe373d25





    Best Regards from Miami

    David
    Last edited by david gonzalez; 12-08-2013 at 12:35 AM. Reason: Sorry, i forgot the code was url

  17. #17
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I generate all possible unique arrangements of 5 numbers

    @ david gonzalez thanks for that link ,replacing that line of code has done the trick for xlsm, good find
    ok here is the modified work book
    ive remmed out the old code line and added the new
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thank you @ martindwilson. Your macro works perfectly! I am really grateful to you for this neat solution. I will use for organising team workshops, whereby I arrange several permutations of group members to discuss topics, sequentially, and without meeting the same group members. Many thanks!

  19. #19
    Forum Contributor
    Join Date
    10-21-2012
    Location
    miami, florida usa
    MS-Off Ver
    Excel 2007
    Posts
    260

    Re: How do I generate all possible unique arrangements of 5 numbers

    Hi, Mr MartinWilson and Mr Newdoverman,

    Thank you very much and your welcome.


    Best Regards from Miami

    David

  20. #20
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thanks for the link....interesting!

  21. #21
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thank you for the feedback. It was fun to see an answer slowly take shape one step at a time.

  22. #22
    Registered User
    Join Date
    12-07-2013
    Location
    London
    MS-Off Ver
    Excel Mac 2011
    Posts
    9

    Re: How do I generate all possible unique arrangements of 5 numbers

    Thank you all for contributing solutions to this problem I have had for a while. I will check it out and seek your advice on how to finesse the solution for my training groups. Regards..J

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-16-2013, 02:46 PM
  2. Formula to generate unique random numbers?!?
    By aims in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-07-2013, 03:14 PM
  3. Replies: 3
    Last Post: 08-21-2012, 07:28 PM
  4. Need to generate unique serial numbers using algorithm
    By Alseikhan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2006, 03:50 AM
  5. generate unique random numbers
    By Stephen Larivee in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 03-28-2006, 08:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1