VBA to format Pivot Table measure (PowerPivot) not working

losamfr17

Board Regular
Joined
Jun 10, 2016
Messages
149
Hi,

I have a data model which I use to create a pivot table. I am using multiple measures in the same pivot table ($'s and %'s).
The one of interest can be referenced in my code as such: "ActiveSheet.PivotTables("PivotTable2").CubeFields("[Measures].[YTD % Chg (DS)]")."

I need a code to automatically change the number format of that measure to "0%;[Red]-0%" in my pivot table.
This needs to be in VBA because I created buttons that allow report users to toggle from one product sales info to another. I want the % chg year over year to formatted every time the pivot table is changed.

When I use the macro recorder, the following code is generated, but it doesn't work when I try to run it. I don't understand why.
VBA Code:
    With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
        "[Sell Out].[Chain Category].[Chain Category]")
        PivotItems().Visible = "0%;[Red]-0%"
    End With
End Sub

Could you please help? Any guidance would be appreciated.
Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,832
Messages
6,121,847
Members
449,051
Latest member
excelquestion515

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