[VBA] Hiding rows in PivotTable

  • Thread starter Thread starter xpan
  • Start date Start date
X

xpan

Hi,

I have PivotTable in Excel 2003. In "Row Fields" there is dimension called
[DepartmentEmployee] which consists of [Department] and [Employee] levels.
To hide rows I used the following code:
Sub Hide()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each pf In pt.RowFields
For Each pi In pf.PivotItems
pi.Visible = False
Next pi
Next pf
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

The problem is, that when the code is done there is no change in the layout
of PivotTable.What went wrong?

In this code "for" loops are iterated for Departments and Employees that are
shown in the current layout of PivotTable.
What should I do to make "for" loops iterate for all Departments and
Employees (even the hidden ones).

Thanks for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top