循环浏览选项卡的子集以隐藏自动筛选箭头

时间:2018-08-21 17:01:20

标签: excel vba excel-vba

我试图遍历选项卡的子集,以在每个选项卡中的单个表上隐藏自动过滤器箭头。如果我在每个选项卡上单独执行.ShowHideFilter = False,则工作正常。我假设我没有正确命名.ShowHideFilter。我收到“下标超出范围”错误。

Sub HideFilterArrows()
Dim ws As Worksheet
With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

For Each ws In Worksheets
    Select Case LCase(ws.Name)
        Case "mastersheet", "merge", "index", "control", "Timeline", "chartdata"
        Case Else
            'Go to next worksheet
            Worksheets(ws.Name).Activate
            ActiveSheet.ListObjects(1).ShowAutoFilter = False
    End Select
Next

With Application
    .ScreenUpdating = True
    .EnableEvents = True
End With
End Sub

1 个答案:

答案 0 :(得分:0)

尝试一下,虽然不漂亮,但是可以。

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
    Select Case ws.Name
        Case "mastersheet", "merge", "index", "control", "Timeline", "chartdata"

        Case Else
            Dim x As ListObject 
            For Each x In ws.ListObjects
                x.ShowAutoFilter = False
            Next x
    End Select
Next