问题
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).
Regards
Greg
回答1:
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
来源:https://stackoverflow.com/questions/10203160/deleting-duplicates-with-vba-excel-2003