J
Jay Gustafson
Hello,
I am using a macro to hide all items in a pivot tables. It's exactly what I want, but this code leaves the last item in the list. What do I edit so even the last item is hidden?
Here is the code...
Hide Items -- Excel 97/Excel 2000
In previous versions of Excel, where there is no Show All checkbox, you can use programming to show or hide multiple fields. The following code hides all items, except the last item, in all row fields.
To hide column fields, change pt.RowFields to pt.ColumnFields.
Sub HidePivotItemsVisible()
'hide all pivot items in all tables on sheet
'except last item
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each pt In ActiveSheet.PivotTables
For Each pf In pt.RowFields
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi.Visible = False Then
pi.Visible = True
Else
pi.Visible = False
End If
Next
Next
pf.AutoSort xlAscending, pf.SourceName
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I am using a macro to hide all items in a pivot tables. It's exactly what I want, but this code leaves the last item in the list. What do I edit so even the last item is hidden?
Here is the code...
Hide Items -- Excel 97/Excel 2000
In previous versions of Excel, where there is no Show All checkbox, you can use programming to show or hide multiple fields. The following code hides all items, except the last item, in all row fields.
To hide column fields, change pt.RowFields to pt.ColumnFields.
Sub HidePivotItemsVisible()
'hide all pivot items in all tables on sheet
'except last item
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each pt In ActiveSheet.PivotTables
For Each pf In pt.RowFields
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi.Visible = False Then
pi.Visible = True
Else
pi.Visible = False
End If
Next
Next
pf.AutoSort xlAscending, pf.SourceName
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub