Yes: instead of enumerating through the pivotfield's pivot items you simply use the .ShowDetail
property of the pivotfield itself e.g.:
Replace
For Each pi In .PivotItems
pi.ShowDetail = False
Next pi
With
.ShowDetail = False
Question
I have built a report based on a pivot table which feeds from a data table. The detail is quite long (tens of thousands of lines) and the user wishes the data to be summarized by a specific field so that he can drilldown only on totals that he is interested in.
I have currently succeeded by looping through all pivot items of all pivot tables for a specified field and hiding them. However, this is taking a significant amount of time ( > 15 min) to run. Is there any way to optimize this by using a different process or is there any option to do this task in bulk (through a setting or an option) which could be faster ?
Here is the function that gets called to do this task:
Sub groupByjrnl_id()
Dim ws As Worksheet
Dim pi As PivotItem
Dim pt As PivotTable
Excel.Application.ScreenUpdating = False
Excel.Application.Calculation = xlCalculationManual
For Each ws In Worksheets
If Left(ws.Name, 3) = "rap" Then
Excel.Application.StatusBar = "Groupement des jrnl_id " & ws.Name
For Each pt In ws.PivotTables
With pt.PivotFields("jrnl_id")
For Each pi In .PivotItems
pi.ShowDetail = False
Next pi
End With
Next pt
End If
Next ws
Excel.Application.StatusBar = ""
Excel.Application.ScreenUpdating = True
Excel.Application.Calculation = xlCalculationAutomatic
End Sub
I am using Excel 2007. Thank you !
Solution
Yes: instead of enumerating through the pivotfield's pivot items you simply use the .ShowDetail
property of the pivotfield itself e.g.:
Replace
For Each pi In .PivotItems
pi.ShowDetail = False
Next pi
With
.ShowDetail = False