VBA 基于两列宏删除重复行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40731901/
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
VBA Remove Duplicates Row based on two Column Macro
提问by LT_Orange
I have over 200k records of customer data in my csv file. I want to be able to create a macro that will compare Account # and product name. Since Account # is a primay key it can only be tied to single product name.
我的 csv 文件中有超过 20 万条客户数据记录。我希望能够创建一个宏来比较帐户编号和产品名称。由于帐户# 是主键,因此它只能绑定到单个产品名称。
I want my macro to give the similar output. Right now when i run my macro on over 200k records. I get only 20 rows.
我希望我的宏给出类似的输出。现在,当我在超过 20 万条记录上运行我的宏时。我只有 20 行。
Sub DelDupl()
Dim Rng As Range, Dn As Range, Del As Integer, Msg As Integer
Set Rng = Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
For Msg = 1 To 2
For Del = Rng.Count To 1 Step -1
If Msg = 1 And Application.CountIf(Rng, Cells(Del, "C")) = 1 Then
End If
If Msg = 2 And Application.CountIf(Rng, Cells(Del, "C")) > 1 Then
Rows(Del).EntireRow.Delete
End If
Next Del
Next Msg
End Sub
Thanks in advance!
提前致谢!
回答by
MSDN - Range.RemoveDuplicates Method (Excel): Removes duplicate values from a range of values.
MSDN - Range.RemoveDuplicates 方法 (Excel):从值范围中删除重复值。
Sub DelDupl()
Range("A1").CurrentRegion.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes
End Sub