Is there a way to apply code to all slicers at once, without having to call out each slicer cache and each slicer item in each of those caches?
I have 4 slicers, each has 2 - 104 items in it.
I would like to run some code so that when all items for all caches are TRUE, then data labels are removed for the 10 pivot charts I have.
Else, if any slicer item for any slicer cache is false, then data labels are applied to all pivot charts.
All my pivot charts are on different sheets than the associated pivot tables.
Each pivot table is on its own sheet.
The slicers are on the same sheets as the charts.
I have some code that when the pivot table is updated, in this case via the slicer, then data labels are applied to the pivot charts.
Here is the code:
But I have to have that in each sheet where a pivot table is present, so currently it is on 10 different sheets because there are 10 pivot tables, and each table is on its own sheet.
I would like to simplify this by having code to remove the data labels when all items for all caches are true, but when a change is made to a cache, have it apply the data labels to all charts.
I was thinking that maybe I should relocate my pivot tables to a single sheet, so that I have a single location to run the code for changes, etc. However, some of them are so huge that they would take up a lot of room. It just isn't rational to do it that way in my opinion.
I ran the Record Macro to see what is output when I make a single change to a slicer. This is what I got:
That particular slicer only has 2 items, as you can see. But some of the slicers have 100+ items. I really don't want to have to type out each item for each slicer cache.
Any thoughts?
Preferably, I would like a push in the right direction, a hint, a nudge, or maybe something simple that I can research, analyze, and build upon. I am not looking for a complete solution as I don't think that very "fair". I enjoy learning but sometimes I just don't know which direction to go, how to get there, or what is needed.
Thanks for reading!!
-Spydey
EDIT: I should have stated that all the pivot tables come from the same data set. Also, I have linked all slicers to all the pivot tables/charts, so that when one button is pressed in any of the slicers, it affects all the pivot tables and the charts are updated appropriately. Sorry.
I have 4 slicers, each has 2 - 104 items in it.
I would like to run some code so that when all items for all caches are TRUE, then data labels are removed for the 10 pivot charts I have.
Else, if any slicer item for any slicer cache is false, then data labels are applied to all pivot charts.
All my pivot charts are on different sheets than the associated pivot tables.
Each pivot table is on its own sheet.
The slicers are on the same sheets as the charts.
I have some code that when the pivot table is updated, in this case via the slicer, then data labels are applied to the pivot charts.
Here is the code:
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim sr As Series
Dim ws As Worksheet
Dim chtObj As ChartObject
Set ws = ActiveSheet
For Each chtObj In ws.ChartObjects
For Each sr In chtObj.Chart.SeriesCollection
sr.ApplyDataLabels
Next sr
Next chtObj
End Sub
But I have to have that in each sheet where a pivot table is present, so currently it is on 10 different sheets because there are 10 pivot tables, and each table is on its own sheet.
I would like to simplify this by having code to remove the data labels when all items for all caches are true, but when a change is made to a cache, have it apply the data labels to all charts.
I was thinking that maybe I should relocate my pivot tables to a single sheet, so that I have a single location to run the code for changes, etc. However, some of them are so huge that they would take up a lot of room. It just isn't rational to do it that way in my opinion.
I ran the Record Macro to see what is output when I make a single change to a slicer. This is what I got:
Code:
Sub TestingSlicer()
With ActiveWorkbook.SlicerCaches("Slicer_Items_Type")
.SlicerItems("Preferred").Selected = True
.SlicerItems("Non-Preferred").Selected = False
End With
End Sub
That particular slicer only has 2 items, as you can see. But some of the slicers have 100+ items. I really don't want to have to type out each item for each slicer cache.
Any thoughts?
Preferably, I would like a push in the right direction, a hint, a nudge, or maybe something simple that I can research, analyze, and build upon. I am not looking for a complete solution as I don't think that very "fair". I enjoy learning but sometimes I just don't know which direction to go, how to get there, or what is needed.
Thanks for reading!!
-Spydey
EDIT: I should have stated that all the pivot tables come from the same data set. Also, I have linked all slicers to all the pivot tables/charts, so that when one button is pressed in any of the slicers, it affects all the pivot tables and the charts are updated appropriately. Sorry.
Last edited: