Solved

Amend all Pivot Tables in Workbook

Posted on 2011-03-14
2
259 Views
Last Modified: 2012-08-14
Hi Experts!

Please help! I've got a workbook with lots of Pivot Tables, and would like to set the PivotFields and PivotItems across all of them.  I've specified the values in the code below, but I can't get this to run.

Thanks,

Steve
Sub AmendAllPivs()

Dim pt As PivotTable
    
    For Each pt In ActiveSheet.PivotTables

    pt.PivotFields ("Product Name")
        .PivotItems("0").Visible = False
        .PivotItems("DIS01").Visible = False
    pt.PivotFields ("LTV Band")
        .PivotItems("85").Visible = False
        .PivotItems("90").Visible = False
        .PivotItems("95").Visible = False
        .PivotItems("100").Visible = False
        .PivotItems("0").Visible = False
    End With
    Next pt

End Sub

Open in new window

0
Comment
Question by:scsnow2310
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 50 total points
ID: 35129445
You are missing With..End With blocks:
Sub AmendAllPivs()  
  
Dim pt As PivotTable  
      
    For Each pt In ActiveSheet.PivotTables  
  
    With pt.PivotFields ("Product Name")  
        .PivotItems("0").Visible = False  
        .PivotItems("DIS01").Visible = False
    End With
    With pt.PivotFields ("LTV Band")  
        .PivotItems("85").Visible = False  
        .PivotItems("90").Visible = False  
        .PivotItems("95").Visible = False  
        .PivotItems("100").Visible = False  
        .PivotItems("0").Visible = False  
    End With  
    Next pt  
  
End Sub

Open in new window

0
 

Author Closing Comment

by:scsnow2310
ID: 35130483
Many thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
excel filters 2 28
Automatic sort formula 8 49
excel 2016 program to loop through scripts to apply filename 2 19
VBA Works in Excel 2010 Not 2016 Help! 5 17
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now