用于检测自动过滤器的 If 语句,即使未过滤任何内容

If statement for detecting autofilter, even when nothing has been filtered

我已经搜索过这个但还没有找到任何东西。澄清一下,我正在寻找一个简单的 if 语句,用于在 none 存在的情况下应用自动过滤器,或者如果已经存在则什么都不做。

我认为解决方案是:

If ActiveSheet.FilterMode = False Then
    Selection.AutoFilter
end if

但这只检测过滤后的数据。如果过滤器已经到位并且您执行此行...

Selection.AutoFilter

过滤器消失了,我的代码今天很糟糕。有没有简单的解决方案?

你很接近:

If ActiveSheet.AutoFilterMode = False Then Selection.AutoFilter