使用“查找和删除”删除重复项突然变得很慢

时间:2018-11-06 14:31:23

标签: excel vba excel-vba

我曾经使用一块宏,这里有人为我提供了一种宏,当在另一列中找到重复项时,可以从其中删除重复项。出于某种原因,删除重复项功能对我而言从来没有用过,继续阅读该功能可能会出错。这是解决该问题的一种方法,并且在另一张纸上效果很好。我重新使用代码,但是现在使用它时,使用一个很小的数据集进行排序(仅350行)非常慢。查找重复副本没有问题,但是使用.delete shift:= up时会出现问题。我这样做是为了使整个列中没有空白单元格,但是现在它说大约3秒钟才能完成每个删除和移位。如果我只使用.clear,则反应是立即的,但这使我在整个列中都留有空白单元格。有没有人知道为什么这段代码需要这么长时间才能完成?

V列是比较列,M列是我要从中删除重复项的列。

Sub Remove_Duplicates()
    Dim M As Range, V As Range
    Dim rc As Long
    rc = Rows.Count
    Set M = Range("M6:M" & Cells(rc, "M").End(xlUp).Row)
    Set V = Range("V6:V" & Cells(rc, "V").End(xlUp).Row)
    Mcnt = M.Count + 5

'Copies SAP Batch summary data into New Batch Summary
If Range("J6") = "" Then
Exit Sub
Else
Range("I6:J6", Range("I6:J6").End(xlDown)).Copy Range("L6:M6")
End If

'Moves From bottom of column M and goes up
    For i = Mcnt To 5 Step -1
        If V.Find(what:=Cells(i, "M"), after:=V(1)) Is Nothing Then
       Else
            'Cells(i, "M").Clear
            Cells(i, "M").Delete shift:=xlUp
        End If
    Next i

'Positions data in the New Batch column
'Call Reposition_Data
End Sub

0 个答案:

没有答案
相关问题