+ Reply to Thread
Results 1 to 10 of 10

Need help creating VBA code to form permutations

  1. #1
    Registered User
    Join Date
    10-02-2017
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    22

    Need help creating VBA code to form permutations

    Hi all,

    I am having trouble finding a code that will create all possible permutations, but within a specific grouping only. For example, below, I want the permutations for A to be only within A and those for B to be only within B. The only codes I have been able to locate so far only consider the full list (ex: would create a permutation of catorange in the example below).

    BEFORE:
    A apple
    A orange
    A banana
    B cat
    B dog
    B lion

    AFTER:
    A appleorange
    A applebanana
    A orangeapple
    A orangebanana
    A bananaapple
    A bananaorange
    B catdog
    B catlion
    B dogcat
    B doglion
    B lioncat
    B liondog


    Any help on getting this code would be greatly appreciated!

    Thank you!

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Need help creating VBA code to form permutations

    Hi Nicole, welcome to the forum. Generating permutations is pretty straight-forward, but a sample workbook showing us exactly how your data is laid out would be useful. Perhaps you could also show us where you want the output.

    To attach a workbook:
    Click Edit Post (or just start a new reply.)
    Click Go Advanced
    Scroll down to Manage Attachments and click.
    Now just Browse for your file, then click Upload. Simple!
    Last edited by leelnich; 10-02-2017 at 04:34 PM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  3. #3
    Registered User
    Join Date
    10-02-2017
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    22

    Re: Need help creating VBA code to form permutations

    Hi,

    I have attached an example excel file. The data list begins in $b$3 and I would like the final data to be pasted in column C.

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Need help creating VBA code to form permutations

    This code assumes your data sheet is currently "active". Paste it in a standard module:
    Please Login or Register  to view this content.
    Last edited by leelnich; 10-03-2017 at 02:45 AM.

  5. #5
    Registered User
    Join Date
    10-02-2017
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    22

    Re: Need help creating VBA code to form permutations

    This is exactly what I need - thank you so much!

    Is there any way you could also show me the code for the same permutation but separated into two columns? In the attached file, I just separated out the letters from the words in columns B and C and would also like to see the permutations listed in columns D and E.

    Thanks again!
    Attached Files Attached Files

  6. #6
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Need help creating VBA code to form permutations

    Like this?

    Original List Permutation Columns
    A apple A appleorange
    A orange A applebanana
    A banana A orangeapple
    B cat A orangebanana
    B dog A bananaapple
    B lion A bananaorange
    B catdog
    B catlion
    B dogcat
    B doglion
    B lioncat
    B liondog
    Please Login or Register  to view this content.
    Last edited by leelnich; 10-03-2017 at 10:31 AM.

  7. #7
    Registered User
    Join Date
    10-02-2017
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    22

    Re: Need help creating VBA code to form permutations

    Thank you for getting back so quickly! I do have one small change - is it possible to update the result to split out the two words into different cells? In this example, the first permutation would put "A" in column D, "Apple" in column E, and "Orange" in column F.

    Thanks!

  8. #8
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Need help creating VBA code to form permutations

    Sure!
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-02-2017
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    22

    Re: Need help creating VBA code to form permutations

    Perfect! Thanks again for all your help - you saved me a lot of time!

    Best,

    Nicole

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Need help creating VBA code to form permutations

    You're most welcome! If fully resolved, please mark your thread as SOLVED (Thread Tools up top). Thanks -Lee

+ 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. Creating combinations or permutations with a macro
    By kufta4 in forum Excel General
    Replies: 3
    Last Post: 10-02-2015, 02:53 PM
  2. Creating combinations or permutations
    By kufta4 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2015, 01:47 PM
  3. VBA form design, need help creating form which adds things to database
    By trickeyd93 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-21-2015, 11:14 AM
  4. Problems with Myrna Larson code for Combinations and Permutations
    By I_max2k2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2013, 05:19 PM
  5. Creating a form in Excel that auto generates a form number
    By nscaife in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2013, 05:53 PM
  6. Myrna Larson code for Combinations and Permutations not working in Excel 07-Overflow
    By PokerJoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2009, 05:58 PM
  7. code for creating form for logging phone call details
    By grant8oy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2007, 03:19 PM

Tags for this Thread

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