+ Reply to Thread
Results 1 to 8 of 8

Finding duplicates and adding their adjacent cells

  1. #1
    Registered User
    Join Date
    03-16-2012
    Location
    Wellington
    MS-Off Ver
    Excel 2010
    Posts
    20

    Finding duplicates and adding their adjacent cells

    Hi, I'm very new to vba and haven't found a thread that matches exactly what I need, although I apologise if this has been discussed before.

    I have thousands of rows to compare each time. I need to find duplicate entries in column A and then add their values which are in column B to put in column C. There is only one worksheet each time.

    Col A can be numbers only or a mixture of numbers and letters. It starts looking like:

    Col A Col B
    THH1234 1
    TKK254 1
    124892 2
    6935 1
    6935 5
    C09654 2

    I want it to end like this below where 6935 are recognised as duplicates and their values of 1 & 5 added to be 6. It doesn't matter if the 6 is in the row for the first or second duplicate.

    Col A Col B Col C
    THH1234 1
    TKK254 1
    124892 2
    6935 1
    6935 5 6
    C09654 2

    It would be ideal if I didn't have to sort column A so that duplicates are next to each other before running the macro but that's not important. Thanks any help is appreciated.
    Last edited by trier; 03-17-2012 at 02:50 PM.

  2. #2
    Registered User
    Join Date
    03-14-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Finding duplicates and adding their adjacent cells

    Have you considered using a pivot table instead of a macro? It is a lot easier and quicker, or is this not an option?
    Dim Prawny As Newb

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding duplicates and adding their adjacent cells

    Try this formula in Column C
    Please Login or Register  to view this content.
    Drag/Fill down

    No need for VBa, and no need to sort.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    03-16-2012
    Location
    Wellington
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Finding duplicates and adding their adjacent cells

    Quote Originally Posted by Prawny View Post
    Have you considered using a pivot table instead of a macro? It is a lot easier and quicker, or is this not an option?

    Thanks for the suggestion Prawny. I didn't consider pivot tables because I'm not too familiar with them myself and the other staff who will need to use this solution have even less idea about them than I do.

  5. #5
    Registered User
    Join Date
    03-16-2012
    Location
    Wellington
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Finding duplicates and adding their adjacent cells

    Quote Originally Posted by Marcol View Post
    Try this formula in Column C
    Please Login or Register  to view this content.
    Drag/Fill down

    No need for VBa, and no need to sort.
    Thanks Marcol. I've tried this. The only shortcoming is that every instance of a repeated item in col A has the cumulative sum of it's values put in col C. So in the example 6935 has col C entry as 1 the first time it appears and then 6 the next time. I want only the total sum of the appearances. Would it help to delete duplicates as it goes?

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding duplicates and adding their adjacent cells

    The easiest way to do this would be ...
    In C2
    Please Login or Register  to view this content.
    Drag/Fill Down as required, then filter out the blanks in Col C.

    If you Need a list without duplicates then this array formula in say E2 for example.
    Please Login or Register  to view this content.
    Confirm with Ctrl+Shift+Enter not just enter, then Drag Down as required
    And in F2
    Please Login or Register  to view this content.
    Drag/Fill Down as required.

    If you go for the second option then using Dynamic Named ranges would be the better option. See the example in this workbook.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-16-2012
    Location
    Wellington
    MS-Off Ver
    Excel 2010
    Posts
    20

    Red face Re: Finding duplicates and adding their adjacent cells

    Quote Originally Posted by Marcol View Post
    The easiest way to do this would be ...
    In C2
    Please Login or Register  to view this content.
    Drag/Fill Down as required, then filter out the blanks in Col C.

    If you Need a list without duplicates then this array formula in say E2 for example.
    Please Login or Register  to view this content.
    Confirm with Ctrl+Shift+Enter not just enter, then Drag Down as required
    And in F2
    Please Login or Register  to view this content.
    Drag/Fill Down as required.

    If you go for the second option then using Dynamic Named ranges would be the better option. See the example in this workbook.
    Thank's so much Marcol that is exactly what I want. There's so much more for me to learn.

  8. #8
    Registered User
    Join Date
    08-17-2014
    Location
    home
    MS-Off Ver
    2014
    Posts
    9

    Re: Finding duplicates and adding their adjacent cells

    I would like to do this but SUBTRACT the adjacent cells. How can this be done?

+ 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