Working with Pivot Tables in VBA

  • Thread starter Thread starter Marshall
  • Start date Start date
M

Marshall

Hi,

I'm just looking at pivot table stuff via VBA for the
first time and am having some hassles:

..PivotItems(x).Visible = True

is returning a 'run time error 1004 app/object defined
error' for PivotItems in a given collection (when the
property is initially manually set to False prior to
running), whereas the same property set to false via
script, on the same item (after manually setting to True)
works fine. I can't work out what is going wrong... I'm
using XL2000. Any ideas??
 
Debrah Dalgleish had written about this:

http://groups.google.com/[email protected]
To prevent the error, set the Sort for the field to Manual. You can do
this in the code, for example:

Sub PivotShowItemAllField()
'For version 2000 -- show all items in specific field
'sort is set to Manual to prevent errors, e.g.
'unable to set Visible Property of PivotItem class
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Salesman")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
With pt.PivotFields("Salesman")
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 xlAscending, pf.SourceName
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

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