Monday 22 December 2014

Microsfot Excel - Macro - How to delete duplicate rows

Watch this example on YouTube

Sub DeleteDuplicated()
    Dim Rng As Range
    Dim ColumnCounter As Integer
   
    Set Rng = ActiveSheet.UsedRange.Rows
   
    For r = Rng.Rows.Count To 1 Step -1
        ColumnCounter = 0
        For Col = Rng.Columns.Count To 1 Step -1
            If Application.WorksheetFunction.CountIf(Rng.Columns(Col), Rng.Cells(r, Col)) > 1 Then
                ColumnCounter = ColumnCounter + 1
            End If
        Next Col
       
        If ColumnCounter = Rng.Columns.Count Then
            Rng.Rows(r).EntireRow.Delete
        End If
    Next r
End Sub

1 comment:

  1. Strange it works in the video but not working for me..

    ReplyDelete