【发布时间】:2017-10-24 05:29:21
【问题描述】:
我目前编写了一个代码来查找从“A3”范围开始到使用的最后一行的重复值;突出显示重复的红色,包括第一个和最后一个实例;按突出显示的颜色过滤,最后从小到大排序。
稍后我将使用这些副本复制到另一张纸上。数据从“A3”列开始到“V3”列和最后一行使用。数据范围从 10,000 到 40,000 行不等,可能更多,具体取决于接收到的数据。
我的问题是这个 marco 运行速度非常慢,有时会死机。有没有其他方法可以达到同样的效果,但更有效、更快?
Sub filtersort ()
Dim sht As Worksheet
Set sht = Worksheets("Sheet1")
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
N = Cells(Rows.Count, "A").End(xlUp).Row
sht.Range("A3:A" & Lastrow).Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
sht.Range("A3:A" & Lastrow).Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("$A$3:$A$" & Lastrow).AutoFilter Field:=1, Criteria1:=RGB(255, _
199, 206), Operator:=xlFilterCellColor
sht.Range("A3:V" & N).Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlYes
End Sub
【问题讨论】:
标签: vba excel duplicates