How can I change the format of the PowerPivot Table based on slicer selection

Needtoknow

Board Regular
Joined
Apr 21, 2006
Messages
73
I am trying to change the format of the powerpivot table based on slicer selection. I have about 5 different slicers selections. After each selection in the slicer, I would like the format of the table to change colours. Since I am a beginner at coding, I turned on the record macro button and got the following code below and then copied and pasted it into the Sheet1 into the VBA editor. During the record macro, I selected the 'PivotTable Tools' on the ribbon, selected 'Design', and then selected a style format. This is what I got below.

Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
ActiveWorkbook.SlicerCaches("Slicer_JobAsset1").VisibleSlicerItemsList = Array _
( _
"[WorkOrderView].[JobAsset].&[140118]")
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable1").TableStyle2 = "PivotStyleMedium7"
Range("A1").Select
End Sub

I'm not sure what's going on, but when I try it, it seems to loop and nothing happens. Is there an easier way.
Any help would be appreciated.
Thx,
Jim
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Have you tried with conditional formatting? Basically what you need to do is harvest the slicer selection and include it into a cell. Then you do the conditional formatting based on that cell.
I am trying to change the format of the powerpivot table based on slicer selection. I have about 5 different slicers selections. After each selection in the slicer, I would like the format of the table to change colours. Since I am a beginner at coding, I turned on the record macro button and got the following code below and then copied and pasted it into the Sheet1 into the VBA editor. During the record macro, I selected the 'PivotTable Tools' on the ribbon, selected 'Design', and then selected a style format. This is what I got below.

Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
ActiveWorkbook.SlicerCaches("Slicer_JobAsset1").VisibleSlicerItemsList = Array _
( _
"[WorkOrderView].[JobAsset].&[140118]")
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable1").TableStyle2 = "PivotStyleMedium7"
Range("A1").Select
End Sub

I'm not sure what's going on, but when I try it, it seems to loop and nothing happens. Is there an easier way.
Any help would be appreciated.
Thx,
Jim
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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