我有一个删除重复项的宏(基于列A)。它排序P中上升然后删除整个行是一个重复的,所以我可以确保的是,宏只删除最早的行(列P =日期):删除重复项(海量数据,非常慢)
Sub SortAndRemoveDUBS()
Dim Rng As Range
Dim LastRow As Long
Dim i As Long
Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Set Rng = Range("A4:P" & LastRow)
With Rng
.Sort Key1:=Range("A4"), Order1:=xlAscending, key2:=Range("P4"), order2:=xlDescending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End With
For i = LastRow To 2 Step -1
If WorksheetFunction.CountIf(Range(Cells(2, "A"), Cells(i, "A")), Cells(i, "A")) > 1 Then
Rows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
但宏是很慢的。有没有办法加快速度?我认为这是因为他删除了每一个重复的一个。
如果你有很多的公式加上'Application.Calculation = xlCalculationManual'顶端,只记得设置回用'Application.Calculation = xlCalculationAutomatic' –
有在片没有公式。 – Bluesector
@Bluesector为什么列P是日期,列是你的ID? 为什么在你排序后,你不检查单元格(i,1)=单元格(i-1,1)?!?! ? 我试了两种方式,你和我的50K的记录。你的时间是00:01:21,我的00:00:23。 PS:可以是我缺少的东西,请解释一下 – Fabrizio