+ Reply to Thread
Results 1 to 5 of 5

Find duplicate rows based on two column values and group

Hybrid View

  1. #1
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Find duplicate rows based on two column values and group

    Dear All,

    In the attached excel... i need to find the duplicate records based on COLUMN B & COLUMN E, if there are matching records, I have to sum the value present in COLUMN C for that combination and keep only one record.

    Please see the attachment for better understanding.

    Expecting an early response..

    Thanks.
    Attached Files Attached Files

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

    Re: Find duplicate rows based on two column values and group

    Try
    Sub test()
        Dim a, i As Long, ii As Long, txt As String
        With Sheets("data").Cells(1).CurrentRegion
            a = .Resize(, Application.Max(.Columns.Count, 9)).Value
        End With
        With CreateObject("Scripting.Dictionary")
            For i = 1 To UBound(a, 1)
                txt = Join(Array(a(i, 2), a(i, 5)), Chr(2))
                If Not .exists(txt) Then
                    .Item(txt) = .Count + 1
                    For ii = 1 To UBound(a, 2)
                        a(.Count, ii) = a(i, ii)
                    Next
                Else
                    a(.Item(txt), 9) = a(.Item(txt), 9) + a(i, 9)
                End If
            Next
            i = .Count
        End With
        With Sheets.Add.Cells(1).Resize(i, UBound(a, 2))
            .Value = a: .Columns.AutoFit
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Re: Find duplicate rows based on two column values and group

    First of all thanks for your quick response..

    I have tried this code, but its only removing the duplicate row and giving any output.

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

    Re: Find duplicate rows based on two column values and group

    Quote Originally Posted by kevivu View Post
    Dear All,

    In the attached excel... i need to find the duplicate records based on COLUMN B & COLUMN E, if there are matching records, I have to sum the value present in COLUMN C for that combination and keep only one record.
    Missread...
    Replace 9 with 3
                Else
                    a(.Item(txt), 9) = a(.Item(txt), 9) + a(i, 9)
                End If
    to
                Else
                    a(.Item(txt), 3) = a(.Item(txt), 3) + a(i, 3)
                End If

  5. #5
    Registered User
    Join Date
    06-20-2015
    Location
    Chennai, India
    MS-Off Ver
    2010
    Posts
    59

    Re: Find duplicate rows based on two column values and group

    Thanks a lot Jindon... it works fine... you are really a super star.....thanks a million...
    Last edited by kevivu; 07-30-2015 at 12:11 AM. Reason: spelling

+ 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: 8
    Last Post: 11-25-2014, 05:11 PM
  2. [SOLVED] Macro to find duplicate values in a column and add the corresponding rows
    By hoss88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-25-2013, 05:40 AM
  3. Macro to Group Rows Along a Range Based on Values in a Column
    By JHCali in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-06-2013, 10:20 AM
  4. how to filter the rows based on a column which contains duplicate values...
    By Rajesh Ushakoyyala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2013, 10:49 AM
  5. Cut & paste rows based on duplicate column values
    By agolden7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2013, 11:09 AM
  6. Remove rows with duplicate values in one column based on value of another column
    By jolleyje in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-15-2013, 06:20 AM
  7. Group Rows Based on two values in a Column A
    By daillest319 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2012, 03:51 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