使用 VBA 删除重复项 - Excel 2003
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10203160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting Duplicates with VBA - Excel 2003
提问by Greg_C
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).
我想知道是否有人会知道任何可以消除重复项的 VBA 代码。例如,在 D 列中,我想保留 ID 的第一个实例,并删除重复项。


Regards
问候
Greg
格雷格
回答by Moosli
Ok, that should work for you. That Routine delets all double Id'd in the Column C
好的,那应该对你有用。该例程删除了 C 列中的所有双 ID
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

