如何识别应用过滤器的字段

时间:2018-04-09 07:58:50

标签: excel-vba vba excel

我认为这个问题相对容易但我找不到任何东西......

我在Excel 2016中有一个相对较大的设备注册表,包含1300多行和近100列。我可以判断何时应用了过滤器,因为可见行有蓝色文本。

如果不手动查看表格的所有标题行,如何识别哪些字段已应用过滤器并选择该列?

即使它像Excel的内置函数一样简单,比如'Find Special ...'也会很棒。

TIA 约什

1 个答案:

答案 0 :(得分:0)

OzGrid有类似的问题和Stephen Bullen的一些代码

https://www.ozgrid.com/forum/forum/help-forums/excel-general/57953-determine-which-columns-are-filtered

Function FilterCriteria(Rng As Range) As String
    'By Stephen Bullen 
    Dim Filter As String
    Filter = ""
    On Error GoTo Finish
    With Rng.Parent.AutoFilter
        If Intersect(Rng, .Range) Is Nothing Then GoTo Finish
        With .Filters(Rng.Column - .Range.Column + 1)
            If Not .On Then GoTo Finish
            Filter = .Criteria1
            Select Case .Operator
                Case xlAnd
                    Filter = Filter & " AND " & .Criteria2
                Case xlOr
                    Filter = Filter & " OR " & .Criteria2
            End Select
        End With
    End With
Finish:
    FilterCriteria = Filter
End Function