+ Reply to Thread
Results 1 to 6 of 6

Merge column values in one row based on common key

  1. #1
    Registered User
    Join Date
    03-28-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    3

    Merge column values in one row based on common key

    We need a vba script to get the desired output for data in the given input format


    Key -----Val1----- Val2----- Val3
    Key1-----a1
    Key1------------- b1
    Key1------------------------c1
    Key2-----a2
    Key2------------- b2
    Key2------------------------c2
    Key3-----a3
    Key3------------- b3
    Key3------------------------c3




    Desired Ouput:
    ---------------
    Key Val1 Val2 Val3
    Key1 a1 b1 c1
    Key2 a2 b2 c2
    Key3 a3 b3 c3

    The same needs to be applied for data around 50 sheets in the same excel. Also, the number of columns for Val1, Val2, etc goes beyond 20 in many of the sheets. Kindly post your suggestion to automate the same.

    Thanks,
    Last edited by ashokkumar2412; 03-28-2014 at 09:05 AM. Reason: formatting issue with table data

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Merge column values in one row based on common key

    If you have only one value for a key in any given column, select the entire table (including headers) and run this macro:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-28-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Merge column values in one row based on common key

    Thanks a lot for your response. We tried executing your macro for our data. Is working fine for one set of values (Key1). It would be of great help, if the program could be generalised for all the key values (Key1, Key2 ...etc). We have a huge data, more than 100 sheets of around (2000 KB)each. The execution time is very high. Kindly advise on the same.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Merge column values in one row based on common key

    It worked on your example data set - post a shortened data set on which it does not work the way you want. Is it just that you have multiple sheets, or is it not working correctly on the first sheet?

  5. #5
    Registered User
    Join Date
    03-28-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Merge column values in one row based on common key

    Quote Originally Posted by Bernie Deitrick View Post
    It worked on your example data set - post a shortened data set on which it does not work the way you want. Is it just that you have multiple sheets, or is it not working correctly on the first sheet?
    Sorry for the confusion. Actually there is one more column in the key part, Column A(Array Index) i.e., (Array Index in ColA + Key in ColB) forms the unique key, data values start from column C onwards. We missed ColA details in our sample data. Could you please help us providing the updated script to match this scenario ?

    Array Key -----Val1----- Val2----- Val3
    1 Key1-----a1
    1 Key1------------- b1
    1 Key1------------------------c1
    2 Key2-----a2
    2 Key2------------- b2
    2 Key2------------------------c2
    1 Key3-----a3
    1 Key3------------- b3
    1 Key3------------------------c3




    Desired Ouput:
    ---------------
    Array Key Val1 Val2 Val3
    1 Key1 a1 b1 c1
    2 Key2 a2 b2 c2
    1 Key3 a3 b3 c3

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Merge column values in one row based on common key

    Try this version:

    Please Login or Register  to view this content.
    And to do it on every sheet:

    Please Login or Register  to view this content.

+ 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. Merge values from column in one cell, based on duplicates in another column
    By Rawland_Hustle in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-24-2014, 11:04 AM
  2. [SOLVED] Merge cells in a table based on number of common values
    By saidineshbabu in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-17-2013, 11:21 AM
  3. [SOLVED] Excel - Merge rows with common values and concatenate the differences in one column
    By ashina in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2013, 07:01 AM
  4. Excel 2007 : merge 2 sheets that have one common column
    By gbutehorn in forum Excel General
    Replies: 0
    Last Post: 09-06-2011, 01:43 PM
  5. Merge 2 sheets with common ID column
    By imimin in forum Excel General
    Replies: 6
    Last Post: 04-19-2011, 05:15 PM

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