Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Pivot Table Hide Levels in VBA

I was wondering how you'd hide levels in a Pivot Table using VBA. e.g. the
way it's currently done is you right click the level and click on "Hide
Levels" on the pivot table, how can I reproduce that functionality in VBA?

thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Pivot Table Hide Levels in VBA

Hi Brett
Set the visible property of the item to false. If you place this code in a
loop just remember to leave at least one item visible to avoid an error.

ActiveSheet.PivotTables(1).PivotFields(2).PivotIte ms(2).Visible = False

Regards
Mike

"Brett" wrote:

I was wondering how you'd hide levels in a Pivot Table using VBA. e.g. the
way it's currently done is you right click the level and click on "Hide
Levels" on the pivot table, how can I reproduce that functionality in VBA?

thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Pivot Table Hide Levels in VBA

Hi Mike

Thanks. But that doesn't work. I get an error, "Unable to set Visible
property of the PivotItem class".

What I want it to display is as follows:
Say now my pivot table is expanded as follows:
[LEVEL 1] [LEVEL 2] [LEVEL 3] [LEVEL 4]

I want it to collapse the first two 'columns' so it displays as follows:
[LEVEL 3] [LEVEL 4]

Therefor 'hiding' the first two levels.

Regards,
Brett




"MIKE215" wrote:

Hi Brett
Set the visible property of the item to false. If you place this code in a
loop just remember to leave at least one item visible to avoid an error.

ActiveSheet.PivotTables(1).PivotFields(2).PivotIte ms(2).Visible = False

Regards
Mike

"Brett" wrote:

I was wondering how you'd hide levels in a Pivot Table using VBA. e.g. the
way it's currently done is you right click the level and click on "Hide
Levels" on the pivot table, how can I reproduce that functionality in VBA?

thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Pivot Table Hide Levels in VBA

Hi Brett

Try this then
With ActiveSheet.PivotTables(1)
For i = 1 To 2
.PivotFields(i).Orientation = xlHidden
Next i
End With
This moves fields 1 and 2 off the table completely.

or the other way to do it is to set fields 3 and 4 to be the rows
With ActiveSheet.PivotTables(1)
For i = 3 To 4
.PivotFields(i).Orientation = xlrow
Next i
End With

Both ways get you to the same place.

Mike

"Brett" wrote:

Hi Mike

Thanks. But that doesn't work. I get an error, "Unable to set Visible
property of the PivotItem class".

What I want it to display is as follows:
Say now my pivot table is expanded as follows:
[LEVEL 1] [LEVEL 2] [LEVEL 3] [LEVEL 4]

I want it to collapse the first two 'columns' so it displays as follows:
[LEVEL 3] [LEVEL 4]

Therefor 'hiding' the first two levels.

Regards,
Brett




"MIKE215" wrote:

Hi Brett
Set the visible property of the item to false. If you place this code in a
loop just remember to leave at least one item visible to avoid an error.

ActiveSheet.PivotTables(1).PivotFields(2).PivotIte ms(2).Visible = False

Regards
Mike

"Brett" wrote:

I was wondering how you'd hide levels in a Pivot Table using VBA. e.g. the
way it's currently done is you right click the level and click on "Hide
Levels" on the pivot table, how can I reproduce that functionality in VBA?

thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table group levels Bunji Excel Discussion (Misc queries) 3 October 15th 08 06:48 PM
Pivot table totals in low levels of hierarchy Nir Excel Discussion (Misc queries) 0 October 16th 07 10:39 AM
Pivot Table For Running Inventory Levels GarrettD78 Excel Discussion (Misc queries) 0 May 15th 07 06:26 PM
Pivot table custom formatting of group levels DannyG Excel Programming 2 February 18th 05 07:20 AM
Pivot table custom formatting of group levels DannyG Excel Programming 0 February 16th 05 01:59 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"