+ Reply to Thread
Results 1 to 18 of 18

Combine rows with duplicate items in one cell and merge values in other cell

  1. #1
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Combine rows with duplicate items in one cell and merge values in other cell

    Hello,
    I am trying to find duplicate values in one column and combine the values of another column and separate them with a delimiter e.g. ";". I may have more than 3 columns.

    Before
    before.JPG

    After
    after.JPG


    I appreciate your help

    Nick
    Attached Files Attached Files
    Last edited by Niclal; 08-29-2014 at 06:05 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    You need to post more information about the input data etc.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    I have uploaded a test file.
    As I mentioned earlier, I need something that I could use even if I have more than 10 columns.
    Thank you so much to everyone.

    N

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Apologies, i completely missed that, just saw the images.

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Please Login or Register  to view this content.

    You need to add a reference to microsoft scripting runtime.

    You can use a collection instead of the scripting.dictionary

    Cheers

  6. #6
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    I had a bash at this, I'm not the most experienced coder, but adapted a few bits of code I have used in the past to come up with a solution. Looks pretty inefficient compared to nathansav's response but maybe there is something useful you can use in here anyway!

    Relies on the data being sorted first to work (which is within the code):

    Please Login or Register  to view this content.
    All the best.
    Last edited by Chriz; 08-29-2014 at 07:27 AM. Reason: made an error with column sortation

  7. #7
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hi,
    How can the code be changed in case I have 10 columns instead of 3? Is there a way of making the code more flexible when it comes to number of columns?
    Cheers,
    N

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    You'll need to change all the arr(i,x)'s in my code, so arr(i,1) ...... arr(i,10)

    You could have a value for the number of columns, and add a for next loop in to build this arr(1,x)....arr(1,y) line.

  9. #9
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hi N,

    I have made my code a bit more flexible using the 'last column' as a variable, but I'm not sure if I can make the part where it concatenates the data any more flexible, sadly I do not have the knowledge myself with that kind of thing. I'll have a think about it, new code:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hi Both,
    Many thanks for all your efforts.
    I am still wondering how to add a value for the number of columns, and add a for next loop in to build this arr(1,x)....arr(1,y) line
    I am not very proficient in VBA.
    Cheers,
    N

  11. #11
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hi N,

    I think I've sussed it, but you may want to do some testing to see if it performs as required, as I say I'm no pro, but this seemed to work on a couple of test runs:

    Please Login or Register  to view this content.
    Cheers

    Chriz

  12. #12
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hello everyone,
    Anybody with other ideas?
    Very much appreciated
    N

  13. #13
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hello Everyone,
    Could someone please help me revise the code such that it can be used for more than 2 columns and also duplicates are removed:
    Thank you so much

    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    @Niclal

    Please Login or Register  to view this content.
    It would also be nice if you respond on the solution of Chriz in #11.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  15. #15
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Hi Criz,
    I did really appreciate all your efforts, and your code solved the problem; I just had to revise it a bit.
    I am just looking for alternatives to make the solution more flexible, i.e. for more than 3 columns and also using Scripting.Dictionary.

    Any thoughts from anyone?
    N

  16. #16
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    I answered you back in post 8 for how to change my code.

    you'll need to change

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Did the post nor the 3 not give you any hints?

    If you had alook at my code, did some investigation you'd see that passing an array to a range, gives the same amount of columns. Keep posting back isnt the way, you could have solved this yourself sooner.

  17. #17
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    Sorry Nathansav,
    But your code didn't help. I have already tried it. That's why I put my code and hope that you can help me extend it to more than 2 columns.
    Thank you
    N

  18. #18
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combine rows with duplicate items in one cell and merge values in other cell

    I tested my code and it did work on your sample data.

    All the best in finding someone to do it for you.

    Cheers

+ 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. combine/merge 2 rows together using duplicate colomn
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2013, 03:08 PM
  2. Merge duplicate rows and combine data in some of the same columns
    By Ken.runciman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2013, 11:43 PM
  3. Merge duplicate row cells, but combine unique cell values (Macro)
    By jcornale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2012, 06:40 PM
  4. Replies: 1
    Last Post: 09-13-2011, 04:33 PM
  5. Macro for VLookup: Combine/Merge Data and Insert/Duplicate Rows
    By choofrfreoer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2011, 04:10 AM

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