Hiding Items in a Pivot Table

In the previous example procedure, you grouped the data in the PivotReport by year based on the OrderDate field. To hide some of the grouped data, you can set the Visible property of the PivotItem object to False. For instance, the following procedure will hide the 1996 column of data in the PivotTable report presented in Figure A-7.

Sub Hide1996Data()

Dim myPivot As PivotTable Dim myltem As Pivotltem Dim strFieldLabel As String strTitle = "1996"

Set myPivot = ActiveSheet.PivotTables(l) For Each myltem In myPivot.PivotFields("OrderDate").PivotItems If myltem.Name <> strTitle Then myltem.Visible = True

Else myltem.Visible = False End If

Next End Sub

0 0

Post a comment