我如何选择一个数组中的多个切片器项目?

问题描述 投票:0回答:1

我正在尝试在切片器中为数据透视表选择多个项目。

我创建了一个包含所有应选择项目的数组。我的代码仅选择一项。

For cnt = UBound(Visible_Both_Years) To 0 Step -1

'filled array
MsgBox Visible_Both_Years(cnt)

'Loop through filter 
With k
    For Each l In .PivotItems
        Select Case l.Name
            Case Is = Visible_Both_Years(cnt)
                l.Visible = True
            Case Else
                l.Visible = False
        End Select
    Next

End With

我是VBA的新手。

arrays excel vba pivot slicers
1个回答
0
投票

没有必要遍历数组,请尝试...

'Loop through filter
With k
    .ClearAllFilters 'clear any existing filters
    For Each l In .PivotItems
        If IsError(Application.Match(l.Name, Visible_Both_Years, 0)) Then
            l.Visible = False
        End If
    Next
End With

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.