+ Reply to Thread
Results 1 to 7 of 7

Nested loops + concatenate values based on match

  1. #1
    Registered User
    Join Date
    07-24-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    91

    Nested loops + concatenate values based on match

    Sorry for the uninforming title.

    My task is quite simple but I need this to be done in a macro (instead of filtering) and it has proven surprisingly difficult for me.

    I have 3 columns (A,B,C) and an open-ended list of items (rows).
    - A (category): gives the item's category (multiple items have the same category)
    - B (value): item's value (text) which may not be unique among items
    - C (selection): takes value TRUE or FALSE

    I would need a macro that would report (separately for each category) the list of values taken by items that have been selected (i.e. for which column C equals TRUE). I would need the output to be a text string looking like this:

    - Name of category 1: value1.1, value1.3, value1.5
    - Name of category 2: value2.3
    - Name of category 3: no item was selected for category 3

    Here is a simplified example of my excel file Template.xlsx.

    Many thanks!

    PS: while the example has 3 different categories, this will vary in practice so the code should be robust to any number of categories ideally.
    Last edited by olivierpbeland; 03-22-2013 at 02:25 PM.

  2. #2
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Nested loops + concatenate values based on match

    this should do it. File attached, code below. Make sure the sheet name is "Output"
    Please Login or Register  to view this content.
    Attached Files Attached Files
    pls click the star if you liked my answer!

  3. #3
    Registered User
    Join Date
    07-24-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Nested loops + concatenate values based on match

    Thanks for the quick answer. As I said in the original post, I will have more then these 3 categories in practice. Is it possible to first have the code list all the unique categories in column A and then basically run your code for each of these?

    Thanks.

  4. #4
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Nested loops + concatenate values based on match

    here you go
    Attached Files Attached Files

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Nested loops + concatenate values based on match

    Hello olivierpbeland,

    Ths attached workbook contains the macro below. The macro does not require the data to be grouped by category nor does it care how many there are. It automatically determines the unique number of categories and combines only like values that are marked true. The result is displayed on the worksheet "Output". A button has been added t0 the sheet to run the macro.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    12-28-2009
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Nested loops + concatenate values based on match

    another approach

    Please Login or Register  to view this content.
    Osvaldo

  7. #7
    Registered User
    Join Date
    07-24-2011
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: Nested loops + concatenate values based on match

    Works like a charm. Thanks Leith and Osvaldo.

+ 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