Extract duplicate records

QueenS

New Member
Joined
Oct 27, 2009
Messages
18
Hi

I've just gone through a cumbersome process of trying to extract duplicate records from a huge masterfile of 600K+ records.

I've scoured the web and I must say, there's a lot of fake sites out there and then some which are trying to get people to pay for the answers which is really frustrating. So thank you MrExcel.com for being a really genuine website with awesome reliable knowledge base to draw on.

Having said that, I put forth my issue ;) and hope someone with superior knowledge can make my work easier.

thanks to mirabeau, i was able to use the code posted on: http://www.mrexcel.com/forum/showthread.php?t=526956

except that it just removed the duplicate records to the "Duplicates" spreadsheet and kept the unique ones.

What I want is a total separation of duplicate records and unique ones with all duplicate records separated onto the "Duplicates" spreadsheet - so that no record has a duplicate in the other spreadsheet.

Help!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Modified mirabeau's code

Code:
Sub duplicstuff()
    Dim t      As Single
    t = Timer
    Dim d As Object, x&, xcol As String
    Dim lc&, lr&, k(), [COLOR="Red"]e[/COLOR]
    xcol = [COLOR="Red"]"A"[/COLOR]
    lc = Cells.Find("*", after:=[a1], searchdirection:=xlPrevious).Column
    lr = Cells.Find("*", after:=[a1], searchdirection:=xlPrevious).Row
    ReDim k(1 To lr, 1 To 1)
    Set d = CreateObject("scripting.dictionary")
  [COLOR="Red"]  e = Cells(1, xcol).Resize(lr)
    For x = 1 To lr
        If Not d.exists(e(x, 1)) Then
            d(e(x, 1)) = x
            k(x, 1) = 1
        Else
            k(d(e(x, 1)), 1) = ""
        End If
    Next x[/COLOR]
    If d.Count = lr Then
        MsgBox "No duplicates"
        Exit Sub
    End If
    Cells(1, lc + 1).Resize(lr) = k
    Range("A1", Cells(lr, lc + 1)).Sort Cells(1, lc + 1), 1
    x = Cells(1, lc + 1).End(4).Row
    Cells(x + 1, 1).Resize(lr - x, lc).Copy Sheets("Duplicates").Range("A1")
    Cells(x + 1, 1).Resize(lr - x, lc).Clear
    Cells(1, lc + 1).Resize(x).Clear
    MsgBox "Code took " & Format(Timer - t, "0.00 secs")
    MsgBox lr & " rows" & vbLf & lc & " columns" & vbLf & _
           lr - x & " duplicate rows"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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