Forum Discussion

Brett745's avatar
Brett745
Copper Contributor
Jul 15, 2021
Solved

Excel fails to remove dupllicates in simple file

I'm using the Remove Duplicates function on simple data sets (usually 20-40 items). Excel fails to remove duplicates, and the feedback received in 'completed' dialogs doesn't seem to be consistent or...
  • HansVogelaar's avatar
    HansVogelaar
    Jul 16, 2021

    Brett745 

    Run this macro. Please test on a copy of your data first.

    Sub RemoveDups()
        Dim rng As Range
        Dim r As Long
        Dim m As Long
        Dim c As Long
        Application.ScreenUpdating = False
        m = Range("A:D").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Set rng = Range("A2:D" & m)
        For c = 4 To 1 Step -1
            m = Cells(Rows.Count, c).End(xlUp).Row
            For r = m To 2 Step -1
                If Application.CountIf(rng, Cells(r, c).Value) > 1 Then
                    Cells(r, c).Delete Shift:=xlShiftUp
                End If
            Next r
        Next c
        Application.ScreenUpdating = True
    End Sub

Resources