需要VBA代码取消选择所有切片器项目

时间:2014-03-13 08:25:03

标签: excel-vba vba excel

ActiveWorkbook.SlicerCaches("Slicer_xxxxx").ClearManualFilter

我需要取消选择所有切片器项目。 我试过这个

For i = 1 To numberOfItems
On Error Resume Next
.SlicerItems(i).Selected = False
Next i

请帮忙

1 个答案:

答案 0 :(得分:5)

Public Sub unselectAllBut(slicerName As String, newSelection As String)
ThisWorkbook.SlicerCaches(slicerName).SlicerItems(newSelection).Selected = True
Dim slc As SlicerItem
For Each slc In ThisWorkbook.SlicerCaches(slicerName).SlicerItems
    If Not slc.Caption = newSelection Then
        slc.Selected = False
    End If
Next slc
End Sub

试试这个! :)

例: unselectAllBut(UrSlicerName,项目标题,你要选择)