我如何 select 多个带有数组的切片器项目?

How can I select several slicer items with an array?

我正在尝试 select 切片器中的几个项目作为枢轴 table。

我创建了一个数组,其中包含应选择的所有项目。我的代码只有 select 一项。

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的新手。

不需要遍历你的数组,试试...

'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

希望对您有所帮助!