【问题标题】:How can I select several slicer items with an array?如何使用数组选择多个切片器项目?
【发布时间】:2020-01-24 13:07:06
【问题描述】:

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

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

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

【问题讨论】:

  • 变量k 应该在这里是什么? Excel.Worksheet?

标签: arrays excel vba pivot slicers


【解决方案1】:

没有必要循环遍历你的数组,试试...

'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

希望这会有所帮助!

【讨论】:

  • 哇,谢谢!有时它可以很容易。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
相关资源
最近更新 更多