简体   繁体   English

删除由变量设置的自动过滤器

[英]Removing an Autofilter that is set by variable

I'm having some trouble removing an autofilter that is set by a variable. 我在删除由变量设置的自动过滤器时遇到了一些麻烦。 I have tried everything I could think of/find online. 我尝试了所有我能想到的/在网上找到的一切。 Nothing seems to be able to remove it. 似乎无法删除它。 Any suggestions? 有什么建议么?

Dim CashRange As Range
Set CashRange = Range("L2:L50000")
CashRange.AutoFilter 1, "CASH"
CashLabeledRows = ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
CashRange.Parent.AutoFilter.Range.Cells.Interior.ColorIndex = 6
CashRange.Parent.AutoFilterMode = False

Have a look at this examples, maybe they will be helpfull. 看看这个例子,也许它们会有所帮助。

If ActiveSheet.FilterMode = True Then 'checks if there are any filters turned on!?
If ActiveSheet.AutoFilterMode = True Then 'if there are filters at all(what so ever)
ActiveSheet.ShowAllData  'Turns off all filters(select all), but not remove them

This is not sequence code, Every line is just for it self. 这不是序列代码,每一行都是针对自己的。 But it can be combined with each other. 但它可以相互结合。

Not the optimal answer but after some testing over different data types present in the form, I determined that the filter issue was only present when "CASH" was not present in any cell of the L column. 不是最佳答案,而是对表格中存在的不同数据类型进行了一些测试之后,我确定仅当L列的任何单元格中都不存在“ CASH”时才出现过滤器问题。

I decided the best way to combat this for the time being was to do a FIND on the column for the CASH value. 我认为目前最好的解决方法是对列中的CASH值进行查找。 Then based on the response, I had a GoTo defined for before and after the above vba. 然后根据响应,在上述vba之前和之后定义了GoTo。 Basically skipping if it was unnecessary. 如果没有必要,基本上跳过。

Thanks everyone for your time and input. 感谢大家的时间和投入。 Code posted below for reference. 代码在下面发布以供参考。

Dim t As Range
Set t = Columns("L").Find("CASH", LookAt:=xlWhole)
If t Is Nothing Then
        GoTo AfterCashYellow
    ElseIf Not t Is Nothing Then
        GoTo CashYellowFill
End If 

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

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