+ Reply to Thread
Results 1 to 6 of 6

Lookup numbers and concatenate them in a different cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Lookup numbers and concatenate them in a different cell

    Hi,

    Can one of VBA gurus please help me with the VBA code and Excel formula? The data is attached in the spreadsheet: "Product IDs".
    The data is a set of Master Product IDs (parent) and the Linked to them Products (children). I need to create a relationship between unique parents (Master Product IDs) and their children (Linked Products)

    From the Data Set table, need to vlookup the unique value in column A (Master Product ID) and return comma delimited (concatenated) corresponding values from column B (Linked Products). So, the result will be as shown in Table 2. Ideally, I would need the results as shown in the Table 3 as an output in the attached spreadsheet. There are only three unique families in Table 3. But if it is difficult to do, then Table 2 results will do.

    I would really appreciate your help. Thank you in advance!

    Table 1
    DATA SET
    Master Product ID Linked Products
    11 1
    11 2
    11 3
    11 4
    4 11
    4 3
    4 2
    4 1
    3 1
    3 2
    3 4
    3 11
    2 1
    2 3
    2 4
    2 11
    1 2
    1 11
    1 4
    1 3
    232 43
    232 85
    232 16
    16 232
    16 85
    16 43
    43 85
    43 16
    43 232
    85 16
    85 232
    85 85
    123 89
    89 123


    I need to


    WOULD RETURN comma delimited Linked Product IDs for each corresponding product like depicted in Linked Products column in Table 2 below.

    Table 2
    Master Product ID Linked Products
    11 1,2,3,4
    4 1,2,3,11
    3 1,2,4,11
    2 1,3,4,11
    1 2,3,4,11,
    232 16,43,85
    16 43,85,232
    43 16,85,232
    85 16,43,232
    123 89
    89 123
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: Lookup numbers and concatenate them in a different cell

    OK, this might not be what you were looking for or expecting ... but maybe just use a Pivot Table. You can use the ConCatAll UDF (by TigerAvatar) to get the comma separated list.

    And you can add buttons to switch between Table 2 and Table 3.

    Relatively easy to implement:

    Option Explicit
    
    Private Sub btnRefresh_Click()
    
    ActiveSheet.PivotTables("PivotTable2"). _
                PivotCache. _
                    Refresh
    
    End Sub
    
    Private Sub btnTable2_Click()
        
    ActiveSheet.PivotTables("PivotTable2"). _
                PivotFields("Master Product ID"). _
                    ClearAllFilters
    
    End Sub
    
    Private Sub btnTable3_Click()
        
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Master Product ID")
        .PivotItems("1").Visible = False
        .PivotItems("2").Visible = False
        .PivotItems("3").Visible = False
        .PivotItems("4").Visible = False
        .PivotItems("16").Visible = False
        .PivotItems("43").Visible = False
        .PivotItems("85").Visible = False
        .PivotItems("89").Visible = False
    End With
    
    End Sub

    Regards, TMS
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: Lookup numbers and concatenate them in a different cell

    Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  4. #4
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Lookup numbers and concatenate them in a different cell

    Hi TMS,

    Thank you so much for your help! I got an error message while creating a pivot table for 25,000 rows, which doesn't let enter "Linked SKUs" into "Column labels". Can you suggest anything to fix this error?

    The error reads: "Excel cannot complete this task with available resources. choose less data or close other applications."

    I would really be appreciative if you help to resolve the error. I'll mark the thread as solved when you or someone, I hope, will help me to fix the error, so I can apply your code.

    thank you!
    Last edited by Neyme; 07-24-2014 at 10:59 AM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: Lookup numbers and concatenate them in a different cell

    Not sure if it's the same error but there are limits on the size of Pivot Tables which I suspect that you have breached. See the MS Article: http://support.microsoft.com/kb/211517

    Looks like we are back to square one.

    I would suggest that you start a new thread, providing a link back to this thread. That way you can generate new interest from the community and provide background information. It will also not be considered a duplicate thread.

    It's a shame but you might need a bespoke VBA solution after all.


    Regards, TMS

  6. #6
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Lookup numbers and concatenate them in a different cell

    Thank you for the recommendations! Much appreciated!

+ 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. Replies: 14
    Last Post: 07-24-2014, 02:20 PM
  2. [SOLVED] Require Function to Lookup and Concatenate Mulltiple Results To Single Cell
    By nuttyengineer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2012, 12:19 AM
  3. Excel 2007 : Lookup and Concatenate help
    By jonesdogg in forum Excel General
    Replies: 1
    Last Post: 06-10-2011, 01:52 AM
  4. How lookup numbers between range numbers in 1 cell ?
    By termal in forum Excel General
    Replies: 4
    Last Post: 02-06-2010, 06:57 AM
  5. Lookup numbers in sheet and assign it's cell reference
    By dgraham in forum Excel General
    Replies: 11
    Last Post: 12-18-2007, 09:48 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