+ Reply to Thread
Results 1 to 18 of 18

Help with macro to Sum duplicate values

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Help with macro to Sum duplicate values

    Dear all,

    I am using the following macro which finds duplicate data and then add the duplicate values together. However, the code only adds together one of the columns (C). I would like the code to add up column C to F.

    Please Login or Register  to view this content.
    For example the input data
    BTT, 2 , 1 , 3, 4,
    CDD, 2 , 4, 5, 6,
    BTT, 2, 1, 1, ,1

    Desired output after the code
    BTT, 4 , 2 , 4, 5,
    CDD, 2 , 4, 5, 6,

    Any help would be very much appreciated. Thank you for your time.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help with macro to Sum duplicate values

    You could try this:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help with macro to Sum duplicate values

    As an option
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Dear Andrew,

    Thank you so much for your help and code. I really appreciate your time and help.

    The code works great...Many Thanks for helping me.

    I have a small issue, the code also Consolidates unwanted rows of data which is highlighted as yellow and i would like to delete those lines.

    Is this possible to do with the same code as above?

    for example:
    input data
    BTT, 2 , 1 , 3, 4,
    CDD, 2 , 4, 5, 6,
    BTT, 2, 1, 1, 1
    ran, 2, 3, 5, 6,


    after the current code
    BTT, 4 , 2 , 4, 5,
    CDD, 2 , 4, 5, 6,
    ran, 2, 3, 5, 6,


    desired output after deleting highlighted rows
    BTT, 4 , 2 , 4, 5,
    CDD, 2 , 4, 5, 6,

    Thank you for your help and time.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help with macro to Sum duplicate values

    After your "For i" row you could try adding:

    Please Login or Register  to view this content.
    Not sure if that will work without seeing your workbook, though.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help with macro to Sum duplicate values

    Have you tried my code, or you do not need it?

  7. #7
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Quote Originally Posted by Andrew-R View Post
    After your "For i" row you could try adding:

    Please Login or Register  to view this content.
    Not sure if that will work without seeing your workbook, though.
    Apology for the late reply, thank you so much for your help. I am very grateful to your time and the code solution.

    I am sorry to say but the deleting the highlighted rows code, did not work. I have attached an sample workbook for further referencing.

    merging_test.xls

    Sheet 1 and sheet 2 shows input data. I ideally the data in sheet2 would be under the data table in sheet1, but i wanted to ask if it was possible to merge the two dataset together from different sheets into sheet1 using the code below, if not, then not to worry.

    The desired output would like the following below (sheet1 updated after the code):
    (for clear representation of output can be seen in sheet3 of the workbook attachment)

    Total, (m), ABS, CMBS, RMBS,
    BTT 2, 2, 2, 2, 2,
    CDD 2, 2, 2, 2, 2,
    CRM 1, 1, 1, 1, 1,
    FTT 2, 2, 2, 2, 2,
    HLL 2, 2, 2, 2, 2,
    WELL 1, 1, 1, 1, 1,
    FARGO 1, 1, 1, 1, 1,


    but I could not get the highlighted row code, to delete unwanted rows.

    Please Login or Register  to view this content.
    I really appreciate your time and help.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help with macro to Sum duplicate values

    This should do what you want.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Dear jindon,

    Thank you very much for your quick response and help. I am sorry to say, the code crashes whenever their is data in column A, B. The code is only merge columns C to H, but I have other data in columns B and A. I only get "run-time mistype error 13" when there is data in column A and B, any help with this issue would be very much appreciated.

    Also, sorry to cause trouble, but is it possible to read sheet2 highlighted data, when it is merged. So when sheet2 data is merged with sheet 1 data, the highlighted rows can be shown to indicate sheet2's data.

    Thank you for your help and time.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help with macro to Sum duplicate values

    File attached.

    If the data structure differ from your sample, need to see the actual data layouts.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Thank you for replying back and your help.

    The actual data is in sheet4 and sheet5, apology for not informing you this earlier, hence i presumed i could change it in the code. However, the code does not have feature to change the sheet variables. I have other data in sheet 1 and onward but for this code, I would like to merge sheet4 and sheet5' data together and display the output in sheet3.

    merging_test with code2.xlsm

    There is only text data in sheet 4's column B and numbers in column A



    Thank you so much for your help and time.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help with macro to Sum duplicate values

    The code should work if you clear col.A & B.

  13. #13
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    I need the data in column A and B for other purposes, is it possible to keep the data in column A and B. Also, is it possible to change the sheet names, so it only merges sheet4 and sheet 5 data.

    Thank you so much for help and time.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help with macro to Sum duplicate values

    You don't have sheet4/sheet5.

  15. #15
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Sorry for the unclear representation of my problem, but the actual data is in sheet 4 and 5, the code does not execute when i place the data in those sheets.

    much help appreciated. Many thanks
    Last edited by missy22; 12-19-2012 at 10:15 AM.

  16. #16
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Help with macro to Sum duplicate values

    Based on your sheet (1) & sheet (2)
    This code will produce in sheet (3), as per you results.
    Please Login or Register  to view this content.
    Regards Mick

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help with macro to Sum duplicate values

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: Help with macro to Sum duplicate values

    Dear Jindon and Mick,

    Thank you so much for your helping me and providing a working solution. Apology for troubling you guys so much. I am very grateful to your help and time as always.

    Thank you so much for both of your hardwork.
    Have a great day.

    Kind regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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