I tried Googling and searched for this one, but just can't get it. All I'm trying to do is thin out the slicers on the activeworksheet page and delete the slicer if it exists.
At the moment I have 6 carvers. I used to have
ActiveSheet.Shapes.Range(Array("Market Segment Name 2", "Line of Business 2" _
, "Customer Name", "Product Group Name", "Product Type Name", "Product Code") _
).Select
Selection.Delete
But it wasn’t good if I already deleted the slicers.
Now I'm trying (note that wb is set as a global variable in a module named "Public")
Option Explicit
Dim sl As Slicer
Dim slName As String
Set wb = ActiveWorkbook
For Each sl In wb.SlicerCaches
If sl.Name = "Market Segment Name 2" Or _
sl.Name = "Line of Business 2" Or _
sl.Name = "Customer Name" Or _
sl.Name = "Product Group Name" Or _
sl.Name = "Product Type Name" Or _
sl.Name = "Product Name" Then
slName = sl.Name
ActiveSheet.Shapes.Range(slName).Delete
End If
Next sl
It seems to me that it should work. I got it working if I go to the SlicerItem level, but I just can't figure out how to access it at the Slicer level ...
Any ideas would be highly appreciated. Thanks.
, , , .