Find Duplicate, sum qty column, delete rest of duplicates

colaps

New Member
Joined
Jan 29, 2013
Messages
37
Hello,

I`m working on a big raw data file and i need to have sum of duplicates.

The file normally has around 16000+ rows and 50 columns. I need to have a VBA code that searches for duplicates, if finding them , adds up the qty and deletes all other duplicates .

I have a working code found on this forum but the issue is speed. Not sure if the first developer of the code had multiple possible duplicates but in my case i have to loop again again and again until no duplicates are found. For 4000+ test rows it took me around 6 minutes ... Can you please propose me a better solution?

Here is a semple of my data:

UniqueIDNetPriceGrossPriceQty-KE
200139983944303
21035048145374
22121263344910
187244215313934
451236963732258
254527435961214
335630281737545
235625716821025
5489372149761076
325661093638729
325617112855441
5841375863491187
32562693231773
12546102465201
12872662339940
325621011515303
06626862558
221240972574628
2212271444191096
568714492861960
952639434713648
2695694500734
95957704242199
95361771701359
365623343021993
878713364623747
878750901688364
878771601388936
541554771309739
158571652474282
898738236007852
5689338567871070
56543580270927
125411532182721
3256444133891162


*Highlighted in red are the duplicates

And here is the code i`m using:
author : Sum and remove duplicate rows

VBA Code:
Sub noDupes()

Dim Cell As Variant
Dim Source As Range
Dim lRow As Long, k As Long, i As Long, q As Long
Dim fullstr As String, fullstr2 As String
Dim arr As Variant
ReDim arr(0)

lRow = Cells(Rows.Count, 1).End(xlUp).Row


Set Source = Range(Cells(2, 1), Cells(lRow, 1))


For Each Cell In Source
   
    If Application.WorksheetFunction.CountIf(Source, Cell) > 1 Then
       
            For k = 2 To lRow Step 1
        fullstr = Cells(k, 1)
        For i = 2 To lRow Step 1
            fullstr2 = Cells(i, 1)
            If k <> i And k < i Then
                If fullstr = fullstr2 And fullstr <> "" Then
                    Cells(k, 5).value = (Cells(k, 4).value + Cells(i, 4).value)
                    Cells(k, 4).value = Cells(k, 5).value
                    arr(UBound(arr)) = i
                    ReDim Preserve arr(UBound(arr) + 1)
                    Range("A" & i).EntireRow.Delete
                End If
            End If
        Next
    Next

       
    End If
Next


Any help is weclomed.

Thank you.
 
Last edited by a moderator:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
That code is nothing like the code you have pointed to. :confused:
Did you actually try the other code?
 
Upvote 0
If you have any problems, just shout.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top