VBA scripting: looping through slicers and 1 item in each

AcidKid

New Member
Joined
Nov 24, 2022
Messages
5
Office Version
  1. 2013
Platform
  1. Windows
I'm working on an automation of my Excel file by using VBA. I'm not experienced at all, but I'm learning OTJ.

We have a file containing a PivotTable which has been converted to OLAP Cubes. We use 35 slicers (with two options, only one of which is needed) on the worksheet to have information about different stores. My goal is to automate the process of manual clicking on the slicer we need, waiting for it to finish calculating, converting the Excel sheet to a PDF, clearing the filter and go on to the next (for 35 times).

I recorded my manual selection and clearing of one slicer:
VBA Code:
ThisWorkbook.SlicerCaches("Slicer_All").VisibleSlicerItemsList = Array("[FiliaalOmzet].[All].&[All]")
ThisWorkbook.SlicerCaches("Slicer_All").ClearManualFilter

The Array part is messing with me to know how to proceed..

I want to loop through all 35 slicers, but only for one item, and have that Array part filled accordingly (changes to that line).
I've found a couple of threads here and on stackoverflow, but I'm not getting there.

VBA Code:
Sub slicerArray()
    Dim slArray as Variant    ' to store the Slicer names in an Array
            slArray = Array("Slicer_All","Slicer_AllExSoi")   'need 33 more added, but I want to test this with these first
    For each slName in slArray
        Call slicers(slName)
    next slName 
End Sub

Sub slicers(slName As Variant)
    Dim slItem As SlicerItem, slDummy As SlicerItem
    Dim slCache As SlicerCache
    Dim sl As Slicer
    Dim slItemsArray() as Variant  ' store values for matching SlicerItems in an Array
    Dim slItemsString As String
    
    slItemsString = "[FiliaalOmzet].[All].&[All];|;[FiliaalOmzet].[AllExSoi].&[AllExSoi]"   ' I need 33 more selections, want to test these two first

    slItemsArray = Split(slItemsString, ";|")

    Set wb = ThisWorkbook
    Set slCache = wb.SlicerCaches(slName)



End Sub


And I'm missing the looping part for all slicers and setting the correct item for the selected slicer...
Anyone can guide me?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top