Seba Robles
Board Regular
- Joined
- May 16, 2018
- Messages
- 73
- Office Version
- 2019
- 2016
- Platform
- Windows
Hello,
I'm trying to loop through all visible slicer items so that I can then copy the updated pivot table based on that slicer selection.
The code below sort of works, it's just not looping through each item on the slicer one by one.
Instead it selects them all and starts by removing one by one. Let's say there are 5 active slicer items, the code currently starts by showing all 5 items, then it shows 4, then 3, etc.
I want to select the first slicer item alone, then the second slicer item by itself, and so on.
Any help is greatly appreciated!!
I'm trying to loop through all visible slicer items so that I can then copy the updated pivot table based on that slicer selection.
The code below sort of works, it's just not looping through each item on the slicer one by one.
Instead it selects them all and starts by removing one by one. Let's say there are 5 active slicer items, the code currently starts by showing all 5 items, then it shows 4, then 3, etc.
I want to select the first slicer item alone, then the second slicer item by itself, and so on.
Any help is greatly appreciated!!
VBA Code:
Sub SlicerTest()
Dim slItem As SlicerItem, slDummy As SlicerItem
Dim slBox As SlicerCache
Set slBox = ActiveWorkbook.SlicerCaches("Slicer_Owner")
'loop through each slicer item
For Each slItem In slBox.SlicerItems
'show all items to start
slBox.ClearManualFilter
'test each item against itself
For Each slDummy In slBox.SlicerItems
'if the item equals the item in the first loop, then select it
'otherwise don't show it (thus showing 1 at a time between the nested loops)
If slItem.Name = slDummy.Name Then slDummy.Selected = True Else: slDummy.Selected = False
'copy table
Range("A5", Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Copy
Next slDummy
Next slItem
End Sub