简体   繁体   English

ActiveSheet.Range AutoFilter RGB 很慢

[英]ActiveSheet.Range AutoFilter RGB Is Slow

I have a macro in Excel VBA and one of the steps within it is performing an AutoFilter on the ActiveSheet range, filter based on color.我在 Excel VBA 中有一个宏,其中的步骤之一是对 ActiveSheet 范围执行自动筛选,基于颜色进行筛选。 This step seems quite time consuming and I am wondering if there might be a quicker way to filter my data?这一步似乎很耗时,我想知道是否有更快的方法来过滤我的数据? Is filtering on color usually slower?颜色过滤通常较慢吗? here's a sample of the code that I am using:这是我正在使用的代码示例:

Selection.AutoFilter
ActiveSheet.Range("$A$1:$AB$100000").AutoFilter Field:=1, Criteria1:=RGB(255 _
    , 199, 206), Operator:=xlFilterCellColor
Rows("2:100000").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

Can you try this.你可以试试这个。 Define the last row of data and don't select.定义最后一行数据,不要选择。 I'm not sure it will make a huge difference but see how it goes.我不确定它会产生巨大的不同,但看看它是如何发展的。

Sub Macro1()

Dim r As Long

r = Range("A" & Rows.Count).End(xlUp).Row

With ActiveSheet.Range("$A$1:$AB$" & r)
    .AutoFilter Field:=1, Criteria1:=RGB(255, 199, 206), Operator:=xlFilterCellColor
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete shift:=xlUp
End With

ActiveSheet.AutoFilterMode = False

End Sub

You don't need to select.你不需要选择。

Sub DoIt()
    Dim rng As Range
    Set rng = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)

    rng.AutoFilter Field:=1, Criteria1:=RGB(255, 199, 206), Operator:=xlFilterCellColor
    rng.Offset(1).EntireRow.Delete
    ActiveSheet.AutoFilterMode = 0
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM