How to remove duplicate rows based on some columns

I have a excel sheet which contains duplicate rows

I want to remove a row if its A C D E F columns are same (Ignore B while calculating duplicates but remove it while removing a row)

At the moment it ignores B while comparison as well as deletion.


In Excel 2013

  1. Select all Data
  2. Select Data Tab -> Remove duplicates
  3. Check 'My columns have headers' if your data has column headers.
  4. Uncheck all columns you would NOT like to use in comparison
  5. Press OK

Done


If I understood you correctly, given rows 1 and 2, you want to delete a row 2 if and only if A1 = A2, C1 = C2, D1 = D2, E1 = E2 and F1 = F2.

This is what I came up with. It could probably be shorter but it does the trick:

Sub DeleteDuplicate()
Dim current As String
ActiveSheet.Range("A1").Activate
Do While ActiveCell.Value <> ""
    current = ActiveCell.Address
    ActiveCell.Offset(1, 0).Activate
    Do While ActiveCell.Value <> ""
        If ((ActiveSheet.Range(current).Value = ActiveCell.Value) And (ActiveSheet.Range(current).Offset(0, 2).Value = ActiveCell.Offset(0, 2).Value) And (ActiveSheet.Range(current).Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value) And (ActiveSheet.Range(current).Offset(0, 4).Value = ActiveCell.Offset(0, 4).Value) And (ActiveSheet.Range(current).Offset(0, 5).Value = ActiveCell.Offset(0, 5).Value)) Then
            ActiveSheet.Rows(ActiveCell.Row).Delete
        Else
        ActiveCell.Offset(1, 0).Activate
        End If
    Loop
    ActiveSheet.Range(current).Offset(1, 0).Activate
Loop
End Sub

What this does is loop through all remaining lines using the ActiveCell as a pointer to the Row being evaluated, and storing the "original" Row's Cell in the current variable. Once the loop ends, the Cell below the current is activated and the inner evaluation loop starts again.

If I messed up somewhere don't hesitate to tell me :)


Add this formula into each row, eg; in column G:

=IF(AND(A2=C2,A2=D2,A2=E2,A2=F2),"DELETE ME","")

This will give a result like:

A   B   C   D   D   F   G
-   -   -   -   -   -   -
x   o   x   x   x   x   DELETE ME
x   x   x   x   x   o   
x   x   x   x   x   x   DELETE ME
x   o   o   x   x   x   

Then create a filter on Column G for rows which say 'DELETE ME', and delete them.