In such cases you may frequently find the application throwing the dreaded Run-time error ‘1004’: Application-defined or object-defined error. You can extend the same code to any other field of the pivot table – visible or otherwise.Ī word of caution though – If you already have already created a slicer of a particular field for one specific pivot table, you may find it difficult to run another code snippet which creates another slicer for the same field without deleting the first one.
We will first construct a slicer based on the “Region” field and then gradually move into carrying out other operations in it using VBA. Imagine a pivot table that shows the sales of a number of product categories in various regions. Name, Caption, Top, Left, Width and Height are used to specify the other parts of the hierarchy. SourceField is the name of the column header of the field for which the slicer is being created. Source is usually the name of the pivot table from which the slicer is being created. My_Slicer_Caches is an object of type SlicerCaches Set My_Slicer = Add(SlicerDestination, ,) Set My_Slicers = Add(Source, SourceField, ) Set My_Slicer_Caches = ActiveWorkbook.SlicerCaches