98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Restricting multiple pivot tables
Restricting multiple pivot tables
Resolved · High Priority · Version 2007
Tarla has attended:
Excel VBA Intro Intermediate course
Restricting multiple pivot tables
Hi,
Code below works when you run it within a worksheet that has a pivot table but I need to run it from a separate worksheet and want it to update all the pivot tables within the workbook.
Sub RestrictPivotTable()
Dim pf As PivotField
With ActiveSheet.PivotTables(1)
.EnableWizard = False
.EnableDrilldown = False
.EnableFieldList = False
.EnableFieldDialog = False
.PivotCache.EnableRefresh = True
For Each pf In .PivotFields
With pf
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next pf
End With
End Sub
Please help.
RE: Restricting multiple pivot tables
Hi Tarla
Thanks for getting in touch. You need to expand your code with another loop that checks all sheets in the workbook for PivotTables.
The following code refreshes all PivotTables in the current workbook.
Sub RefreshAllPivotTables()
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
End Sub
Extending this idea into your code we get:
Sub RestrictPivotTables()
Dim PT As PivotTable
Dim WS As Worksheet
Dim PF As PivotField
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.EnableWizard = False
PT.EnableDrilldown = False
PT.EnableFieldList = False
PT.EnableFieldDialog = False
PT.PivotCache.EnableRefresh = True
For Each PF In PT.PivotFields
With PF
.DragToPage = False
.DragToRow = False
.DragToColumn = False
.DragToData = False
.DragToHide = False
End With
Next PF
Next PT
Next WS
End Sub
I hope this helps.
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Wed 26 Jun 2013: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Add Text to Displayed Numbers in Excel 2010To add text to a number in a cell, you need to go to the Home tab on the Ribbon, and click on the Cells group. Select Format Cells from the drop down menu then Custom from the Category list. In the Type box select General. After the word General, enter a space, then opening quotation marks, then the word you want to type and then closing quotation marks. Click on OK and you have your text! |