当您选择了 1 或 2 个标准时,您可以像这样简单地检索它们
Option Explicit
Sub sample()
Dim rRange As Range
Dim iFiltCrit As Long
'Remove any filters
ActiveSheet.AutoFilterMode = False
Set rRange = Range("A1:B8")
With rRange
.AutoFilter Field:=1, Criteria1:="=1"
Debug.Print Sheet1.AutoFilter.Filters(1).Criteria1
End With
'Remove any filters
ActiveSheet.AutoFilterMode = False
End Sub
当您有超过 2 个条件时,您可以按照您提到的那样循环,因为它们存储在一个数组中。
问题是当过滤器处于非活动状态时,即您可以看到所有内容,然后从内存中清除所有条件。请参阅此示例。我ActiveSheet.ShowAllData
用来显示所有数据。
Option Explicit
Sub sample()
Dim rRange As Range
'Remove any filters
ActiveSheet.AutoFilterMode = False
Set rRange = Range("A1:B8")
With rRange
.AutoFilter Field:=1, Criteria1:="=1"
Debug.Print ">"; Sheet1.AutoFilter.Filters(1).Criteria1
'~~> Show all data
ActiveSheet.ShowAllData
Debug.Print ">>"; Sheet1.AutoFilter.Filters(1).Criteria1
End With
'Remove any filters
ActiveSheet.AutoFilterMode = False
End Sub
快照
因此,我相信一旦显示所有数据,您将无法再检索该信息。