arrays - 如何使用数组选择多个切片器项目?
问题描述
我正在尝试在切片器中为数据透视表选择多个项目。
我创建了一个包含所有应该选择的项目的数组。我的代码只选择一项。
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的新手。
解决方案
There's no need to loop through your array, try...
'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
Hope this helps!
推荐阅读
- python - 如何在 WTForms 中呈现可变长度的 FieldList?
- c# - 得到两个椭圆而不是一个
- java - CreatePlatformSocket() 返回错误:提供的参数无效。端口不可用。退出...同时在 Chrome 上运行 selenium 代码
- sql - 基于特定行条件的列中值的透视和总和
- ddev - 如何在我的 ddev 容器中设置时区?
- asp.net-mvc - 如何创建用于编辑数据的下拉列表?
- javascript - 谷歌条形图中更好的标签
- rest - 用于长时间创建、轮询、交付长时间运行作业的 ASP.NET Web Api 最佳实践
- python - Docker + Python,自有模块的问题
- php - 在laravel中如何将图像文件从一个文件夹移动到另一个文件夹