VBA for Pivot Table - Removing Measures

thedesk

New Member
Joined
Feb 16, 2021
Messages
3
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi there, is there a way to remove all of the available measures rather than listing each one as below ?

Please see below for some sample code.

ActiveSheet.PivotTables("PivotTable1").CubeFields("[Measures].[XXX1]").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").CubeFields("[Measures].[XXX2]").Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable1").CubeFields("[Measures].[XXX3]").Orientation = xlHidden

etc, all the way to about 70.

This removes the measures that I would like. Except i have to specifically name them. Is there a way to remove all measures using one bit of code, or do I have to name them to get them removed?


Thanks in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
it looks like a string you have to make in a loop
VBA Code:
     For i = 1 To 70
          s = "[Measures].[" & Right("XXXX" & Format(i, "0"), 4) & "]"
          MsgBox s
         ActiveSheet.PivotTables("PivotTable1").CubeFields(s).Orientation = xlHidden
      Next
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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