VBA基于两个列宏删除重复行

时间:2016-11-22 00:29:15

标签: excel vba excel-vba macros duplicates

我的csv文件中有超过200k的客户数据记录。我希望能够创建一个比较帐号#和产品名称的宏。由于帐号#是主要密钥,因此它只能与单个产品名称绑定。

我希望我的宏能够提供类似的输出。现在,当我在超过200k的记录上运行我的宏。我只得到20行。

enter image description here

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

提前致谢!

1 个答案:

答案 0 :(得分:1)

MSDN - Range.RemoveDuplicates Method (Excel):从一系列值中删除重复值。

enter image description here

Sub DelDupl()

    Range("A1").CurrentRegion.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes

End Sub
相关问题