+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 : best method for combinatorial concatenation template?

  1. #1
    Registered User
    Join Date
    05-25-2010
    Location
    SF
    MS-Off Ver
    Excel 2003
    Posts
    3

    best method for combinatorial concatenation template?

    What's the best way to permutationally concatenate the information in multiple tabs on a spreadsheet, particularly if you don't know in advance how many rows you'll have in each tab?

    Let's say you want to combine every populated row in tab 1 with every populated row in tab 2 with every populated row in tab 3. But you want this to work as a template, that can accommodate different data each day, and a possibly different number of rows in each tab from day to day. The data in each tab will be pasted in from a different source, where the number of items may vary from day to day, so you want a clean template that will figure out how many combinations there should be, and create all of them for you in a fourth tab.

    So if on a given day tab 1 has three rows:
    G
    H
    I

    and tab 2 has six rows:
    2
    4
    6
    8
    10
    12

    and tab 3 has 2 rows:
    xx
    yy

    and you wanted to concatenate all these items separated by say ":", you'd end up with output rows in the fourth tab like:

    G:2:xx
    G:2:yy
    G:4:xx
    G:4:yy
    G:6:xx
    G:6:yy
    .
    .
    .
    and so forth up to
    I:12:xx
    I:12:yy

    but you want a formula that can automatically or semi-automatically handle days where, for example, tab 1 has 10 rows, tab 2 has 2 rows, and tab 3 has 5 rows, just by looking for the point where the data ends in each tab (where the empty rows begin).

    It would be ok if you have to figure out the total # of daily permutations and copy the formula down manually to accommodate the right number of output rows - that is not a difficult daily task to handle...but the less manual and room for error, the better.

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

    Re: best method for combinatorial concatenation template?

    The simplest way of all to a user would be a macro.

    1) Create a 4 sheet workbook
    Sheet1
    Sheet2
    Sheet3
    Sheet4

    2) Put the data in the first three sheets in column A.

    3) Run this macro and it will create a new listing in Sheet4 for you
    Please Login or Register  to view this content.
    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    _________________
    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!)

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

    Re: best method for combinatorial concatenation template?

    Here's a sample workbook, you can just use this to drop your data into, then click the button on Sheet4.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-25-2010
    Location
    SF
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: best method for combinatorial concatenation template?

    Quote Originally Posted by JBeaucaire View Post
    Here's a sample workbook, you can just use this to drop your data into, then click the button on Sheet4.
    Cool, this works great!

    I also figured out how to customize your code to reference different tabs (changing the "Sheet1" etc. references to their actual names); and accommodate items generated by formulas instead of pasted-in constants (change the SpecialCells reference from xlCellTypeConstants to xlCellTypeFormulas).

    Terrific!

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

    Re: best method for combinatorial concatenation template?

    Good stuff...

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  6. #6
    Registered User
    Join Date
    05-25-2010
    Location
    SF
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: best method for combinatorial concatenation template?

    hmmm, I can't edit the original message, and the followup message does have an edit button, but no "PREFIX" box. ?

  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: best method for combinatorial concatenation template?

    You waited too long Just EDIT the post, GO ADVANCED and add [SOLVED] to the beginning of the title.

    EDIT: I see you did!

  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: best method for combinatorial concatenation template?

    I changed it, JB. The edit button on the original post goes away after two days.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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