Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Amend all Pivot Tables in Workbook

Posted on 2011-03-14
2
Medium Priority
?
265 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

879 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