+ Reply to Thread
Results 1 to 5 of 5

Macro for permutations/combinations?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2009
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    8

    Macro for permutations/combinations?

    Hi,

    I have a sequence of 6 strings (3 each in 2 categories)

    Category Brand(B) : A, B, C
    Category Product (P): D, E, F

    I am trying to work out an sequence like BBBPPP using each ad from the B and P categories and have all combinations, maintaining the BBBPPP order.

    Example:

    ABC DEF
    CBA DEF
    BCA DEF
    ----
    ----
    ----

    Is there a way I can do this in Excel where I can automatically list these combinations? I have been trying to play around with the PERMUT and COMBIN functions with no luck. I want it to output the actual sequence and not the # of iterations possible.

    Any help is appreciated.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro for permutations/combinations?

    svs9j,

    See:

    Myrna Larson, July 25, 2000, Microsoft.Public.Excel.Misc
    http://www.mydatabasesupport.com/for...binations.html

    pgc01
    http://www.mrexcel.com/forum/showthread.php?t=412952

    Sub PermutWords()
    pgc01
    http://www.mrexcel.com/forum/showthread.php?t=371960
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    09-11-2009
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro for permutations/combinations?

    Thank you stanleydgromjr

    I am looking for this exactly, but instead of one word in A1, I want say 3 words in A1, A2, A3 and combination of that. How can I modify the code to do this?


    Write the word in A1

    Try:

    Code:

    Sub PermutWords()
    Dim lrow As Long

    PermutWords1 Range("A1"), "", lrow
    End Sub

    Function PermutWords1(ByVal s As String, ByVal sPermut As String, ByRef lrow As Long)
    Dim l As Long

    If Len(s) = 1 Then
    lrow = lrow + 1
    Range("B" & lrow) = sPermut & s
    Else
    For l = 1 To Len(s)
    PermutWords1 Replace(s, Mid(s, l, 1), ""), sPermut & Mid(s, l, 1), lrow
    Next l
    End If
    End Function

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro for permutations/combinations?

    svs, please take a few minutes to read the Forum Rules, and then edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

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

    Re: Macro for permutations/combinations?

    do you still want an answer for this?
    "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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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