+ Reply to Thread
Results 1 to 10 of 10

Text Combinations

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Text Combinations

    I have the following set of Data for example.

    Please Login or Register  to view this content.
    I want to know what all combinations of the above texts there are.

    i.e.
    Please Login or Register  to view this content.
    etc.. for all the combinations.

    If i already have
    Please Login or Register  to view this content.
    I must NOT ALSO have..

    Please Login or Register  to view this content.
    I'd like a VBA script which I can use to make this happen. The list of values which to retrieve the original raw set of data will sit in cells A1 to A10.

    I hope this makes sense?
    Cheers
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Text Combinations

    Try out the attached Excel 2003 file that combines from 2 to 6 cell values in a delimited list that shows
    all the unique combinations.

    To accomplish this, the code goes through these steps:
    - capture the cell values starting in Cell A1, from column 1, into a dictionary object
    - put the values into an array
    - start the loop and nested loop
    - put the array values in one string, such as “Yes, You, Can, Do, It”
    - check the dictionary and add this string and item count if string not already in the dictionary
    (item count will be 5 in this case)
    - perform a reverse analysis where the string is “It, Do, Can, You, Yes”
    - add this string and item count to dictionary if it is not already there
    - run through inner loop again and do same analysis, this time dropping 1st array element and continue
    looping until analysis of 2 items has been completed
    - Now outside of the inner loop, sort the array randomly and continue from the outer loop again,
    performing the same analysis on a different text string.
    - Discontinue looping when the expected number of unique combinations made has been reached.
    - Capture dictionary data, including text and item counts, to arrays and write to Sheet1
    - Sort the list and add group summary counts to the sheet. All done!


    The secret to the success of this challenge is the Dictionary object, which worked perfectly for storing
    unique lists of data.

    Some controls on the worksheet give you the options of choosing the delimiter, or no delimiter,
    space after delimiter or no space.

    After completing several runs I observed (the obvious) that you always get the same number of rows returned
    for the same number of items to be combined. That’s when I revised the looping code to stop the random analysis
    when the dictionary record count reached the expected results. I hope the attached runs flawlessly for you.
    Jerry
    Attached Files Attached Files

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Text Combinations

    Hi!

    Firstly, I just want to say thank you very much for your effort! I can see the depth you have gone to explain how your logic would work. So thanks again.

    The problem I have with your code is for example in cell B2, you have 'Can, You' and in B5, you have 'You, Can'. To me; this 'combination' should only be displayed once. Preferably with 'You, Can' as I will play 'You' in A2 before A3.

    I hope this makes sense and I hope you are able to advise further

    Cheers

  4. #4
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Text Combinations

    See the Excel 2003 revised attachment that generates a list of text combinations,
    and without duplicating any set of combined items. You can enter up to 10 items,
    in cells A1 thru A10. I believe this will do what you described in your post.

    The use of several dictionary objects allowed the macro to enforce uniqueness of the results.
    The dictionary object can only store unique values.
    Attached Files Attached Files

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Text Combinations

    Hi,

    Is there a way to modify this so i can enter more than 10 items?

  6. #6
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Text Combinations

    Entering more than 10 items to find unique text combinations, and without duplication
    in any combination set, would require a different solution than what I coded.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Text Combinations

    Translation... mark this thread as solved (See Thread Tools above) and start a new thread.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    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: Text Combinations

    There's a workbook that will do this for an arbitrary number of items (until you run out of rows) at https://www.box.com/s/b9b9fc06beb63b9562f9
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Text Combinations

    @ JBeaucaire,

    Hello Jerry,

    Translation...
    You are way too sharp! LOL.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  10. #10
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Text Combinations

    My plan was to give only what was asked for, text combinations up to 10 items.
    Using the 10 digits (0-9) to represent whatever unique values were in column A, rows #1 thru #10,
    made this a 10-items-or-less solution
    Last edited by xLJer; 06-14-2013 at 03:37 PM. Reason: wording

+ 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