LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Manipulating Pivot Tables With Macros

To prevent the error, set the Sort for the field to Manual. You can do
this in the code, for example:

Sub PivotShowItemResetSort()
'For version 2000 -- show all items in field
'sort is set to Manual to prevent errors, e.g.
'unable to set Visible Property of PivotItem class
'returns sort order to previous setting
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim intASO As Integer

Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each pt In ActiveSheet.PivotTables
For Each pf In pt.VisibleFields
intASO = pf.AutoSortOrder
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi.Visible < True Then
pi.Visible = True
End If
Next pi
pf.AutoSort intASO, pf.SourceName
Next pf
Next pt
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


Mike Barron wrote:
I have been trying to automate a pivot table to produce 2
standard reports from a database in a separate
spreadsheet. There are three field items which differ
between the reports. I have recorded a macro to hide the
fields and another to show them. Looking at the code
produced by these it appears simple to set the VISIBLE
property for the items to either FALSEor TRUE to show or
hide these items but although the code for hiding the
items works the macro gives an error when trying to set
the VISIBLE property to TRUE. The error is:

Run-time error 1004
Unable to setthe Visible property of the PivotItem class

An extract of the affected code is below:

With ActiveSheet.PivotTables("Rupee").PivotFields
("Activity No")
.PivotItems("14").Visible = False
.PivotItems("14.1").Visible = True
End With

Only the second one (14.1) gives the error.
Has anyone else had a similar problem and is there a
solution?



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html



 
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
Excel Macros for pivot tables PJS Excel Discussion (Misc queries) 3 June 11th 09 11:30 PM
Macros/Protection/Pivot Tables...HELP KDG Excel Discussion (Misc queries) 0 October 19th 06 08:45 PM
Pivot tables and macros Mike Excel Discussion (Misc queries) 1 January 9th 06 04:53 PM
What's the best way to learn Pivot Tables and using Macros in Exc. Shirley New Users to Excel 3 April 7th 05 12:47 PM
Manipulating Pivot Tables with VBA patriot301 Excel Programming 1 September 25th 03 02:32 PM


All times are GMT +1. The time now is 08:16 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"