Greg_C
Greg_C

Reputation: 11

Deleting Duplicates with VBA - Excel 2003

I was wondering if anyone would know of any VBA code that would get rid of duplicates. For example, in Column D, I want to keep the first instance of the ID, and get delete the duplicate(s).

enter image description here

Regards

Greg

Upvotes: 1

Views: 6333

Answers (1)

Moosli
Moosli

Reputation: 3260

Ok, that should work for you. That Routine delets all double Id'd in the Column C

Option Explicit


Sub DeletDuplicate()
    Dim x As Long
    Dim LastRow As Long
    LastRow = Range("C65536").End(xlUp).Row
    For x = LastRow To 1 Step -1
        If Application.WorksheetFunction.CountIf(Range("C1:C" & x), Range("C" & x).Text) > 1 Then
            Range("C" & x).EntireRow.Delete
        End If
    Next x
End Sub

Upvotes: 4

Related Questions