+ Reply to Thread
Results 1 to 4 of 4

Macro to create combinations of a string

  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    Macro to create combinations of a string

    Hello;

    I am trying to create a macro to do below, but got stuck at the beginning, can anyone point me at the right direction please?

    I have a string like this: 111111111

    What I am trying to do is to get the excel to write down all the combinations of that string on different columns.

    The reason I need to use a seperator like "_" is because _111 and 111_ would mean different things in my case.

    i.e COLUMN1: Combination with 8 would be below; COMBIN(9;8) = 9 new strings

    _11111111
    1_1111111
    11_111111 and so on...

    COLUMN2: Combination with 7 would be below; COMBIN(9;7) = 36 new strings
    __1111111
    1__111111
    1__111111
    1_1_11111 etc...

    I cannot figure out how that loop should work

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Macro to create combinations of a string

    Something like this?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to create combinations of a string

    Millz, this is very good thanks for your help!
    Apologies I could not make myself clear the first time but, the only additional thing is, I need the macro to get the combinations from user as well. For example;

    String: 12345 Combine high: 4 Combine Low: 2

    In this case, Column:A would have COMBIN(5;4)=5 rows, Column:B COMBIN(5:3)=10 rows, Column:C COMBIN(5:2)=10 rows ; Column:D COMBIN(5;1) = 5 rows.

    A B C D
    1 _12345 1__45 1___5 1____
    2 1_2345 12__5 12___ _2___

    The macro currently works perfectly for getting the string from me, but is it possible for it to also ask for the combination numbers also? Although I have been working on your direction for the last couple of hours, could not figure it out.

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Macro to create combinations of a string

    This took a lot of brain juice out of me:

    Try with string: 12345
    Number of combinations: 4
    Please Login or Register  to view this content.

+ 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. [SOLVED] Macro to create combinations
    By CarlosLopez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2013, 02:31 AM
  2. Is there an excel formula to make combinations with string variables?
    By Andersoneagle in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-30-2013, 02:50 AM
  3. list of combinations of string of letters
    By rmb623 in forum Excel General
    Replies: 10
    Last Post: 05-29-2011, 02:12 PM
  4. How do I create a macro to return all possible combinations of letters?
    By k8b in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2010, 10:39 AM
  5. [SOLVED] Macro to add numbers to create combinations that equal certain amo
    By Lauren qt314 in forum Excel General
    Replies: 3
    Last Post: 04-21-2005, 01:06 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