【发布时间】:2017-10-27 12:20:58
【问题描述】:
我希望删除包含 40-50,000 行的数据集中的重复项(保留空白)。 我拥有的当前代码将保留第一个和最后一个实例,但我只需要保留第一个实例,同时删除其余代码。
Sub dltedups()
Dim toDelete As Range: Set toDelete = Sheet1.Rows(999999) '(to not start with
a null range)
Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
Dim a As Range
For Each a In Sheet1.Range("A7", Sheet1.Range("A999999").End(xlUp))
If Not dict.Exists(a.Value2) Then
dict(a.Value2) = 0
Else
If dict(a.Value2) = 1 Then Set toDelete = Union(toDelete,
Sheet1.Rows(dict(a.Value2)))
dict(a.Value2) = a.Row
End If
Next
toDelete.Delete
End Sub
【问题讨论】:
标签: vba excel duplicates