Solved

Amend all Pivot Tables in Workbook

Posted on 2011-03-14
2
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

710 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