0

I am trying to delete duplicate rows from my table and I thought this was straightforward enough looking at other examples online. Unfortunately, I am getting a type mismatch error on my variable. Also, I want the first instance from the bottom to be deleted not the first instance. So if row 5 and 27 are duplicates, I want row 27 to be deleted.

Here is my code:

Sub DeleteDuplicateRows()

Dim Rng As Range
With Worksheets("Database")

Set Rng = Range("C1", Range("Q1").End(xlDown))
    Rng.RemoveDuplicates Columns:=Array(3, 17), Header:=xlYes
End With

End Sub
Community
  • 1
  • 1
Remi
  • 159
  • 3
  • 14
  • Possible duplicate of [Delete all duplicate rows Excel vba](https://stackoverflow.com/questions/16988816/delete-all-duplicate-rows-excel-vba) – Ken White Apr 02 '18 at 16:52

1 Answers1

2

Array(1, 15) is column C and column Q within range C:Q.

Sub DeleteDuplicateRows()
    Dim Rng As Range

    With Worksheets("Database")
        Set Rng = .Range("C1", .Range("Q1").End(xlDown))
        Rng.RemoveDuplicates Columns:=Array(1, 15), Header:=xlYes
    End With
End Sub
  • Is this making sure `C` and `Q` aren't duplicates or is it `C` or `Q`? – Remi Apr 02 '18 at 17:23
  • 1
    C **and** Q. If you want C **or** Q then you need to do it twice; once for C and once for Q. –  Apr 02 '18 at 17:25