【问题标题】:VBA Remove Duplicates Row based on two Column MacroVBA基于两列宏删除重复行
【发布时间】:2017-04-05 12:58:23
【问题描述】:

我的 csv 文件中有超过 20 万条客户数据记录。我希望能够创建一个将比较帐户编号和产品名称的宏。由于 Account # 是主键,因此它只能与单个产品名称相关联。

我希望我的宏提供类似的输出。现在,当我在超过 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

提前致谢!

【问题讨论】:

  • 您是否尝试过使用数据>>删除重复项
  • 所以您只想要具有唯一帐号的行吗?为什么不排序然后遍历它并删除如果等于上面的行?
  • 在您的问题中,您说 由于 Account # 是一个主键,它只能与单个产品名称绑定。 但您真的是说 Since Account # is一个主键,它只能绑定到单个 customer 名称。 ?如果是这样,您应该更新问题,因为目前它不扫描。
  • 如果您需要检查 200K 行,则需要将 Del 声明为 Long 而不是 Integer。 Integer 的最大值为 32,767

标签: vba excel macros duplicates


【解决方案1】:

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

Sub DelDupl()

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

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2016-10-04
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多