excel - VBA:循环遍历Excel过滤器中的条件?

标签 excel vba loops

整个早上我都在想办法解决这个问题。有没有办法循环遍历 Excel 中列过滤器中的条件,同时用条件名称填充数组?过滤器对象似乎只有 criteria1 和 criteria2。抱歉,如果我的任何术语不清楚,我对 Excel 还很陌生。

(这是使用 Excel 2007)

最佳答案

看来,如果您选择了 1 或 2 个条件,那么这些条件将存储在 .Criteria1.Criteria2 中。

但是,如果您有超过 2 个,则 .Criteria1 将成为所选过滤器的数组 - 然后您可以使用...进行迭代...

Dim iFilt As Integer       'This should be set equal to the column 
                           'index you are interested in

Dim iFiltCrit as Integer

For iFiltCrit = 1 To UBound( Sheet1.AutoFilter.Filters(iFilt).Criteria1 )
    Debug.Print Sheet1.AutoFilter.Filters(iFilt).Criteria1(iFiltCrit)
Next

请注意,这仅适用于具有 2 个以上条件的列 - 如何确定是否属于这种情况取决于您 - 这是一个相当笨重的 Excel API(意外惊喜),因为它的类型松散.

关于excel - VBA:循环遍历Excel过滤器中的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9893057/

相关文章:

excel - Findwindow 在 64 位 VBA7 中不起作用

java - 使用 Apache POI 设置 Excel 工作表散点图标记图标的颜色

excel - Access VBA Excel : Formatting Excel and Range Application/Object error

VBA Excel - 将大小写更改为正确大小写

c - C 中的数字金字塔

sql - 从VBA中的数组批量插入到sql中

Excel:运行时错误 '13' 类型不匹配

vba - Excel 中的数组常量

python - 找到达到多个级别的方法

java - do-while 和 while 比较