Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Unable to access visible property of Pivot Items class

Hi,

with the following code I get run-time error 1004 with the above description:

Set pt = ActiveSheet.PivotTables("Pivot_Table")
Set pf = pt.PivotFields("Pivot Class")

With pf
.Orientation = xlColumnField
.Position = 1
For Each pi In pf.PivotItems
If pi.Name = "#N/A" Or "1" Then
pi.Visible = False
Else: pi.Visible = True
End If
Next pi
End With

The error occurs at the line

pi.Visible = False

funnily enough when the test condition of the If statement has failed, i.e.
execution should have skipped this line.

Also, the Orientation property of the PivotField for some reason changes to
xlHidden, after it has been explicitly set to xlColumnField before entering
the If statement. I have a suspicion that this may be behind it, but I don't
know of a way to stop this particular property changing.

Any suggestions?

Thanks
--
There are 10 types of people in the world - those who understand binary and
those who don't.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Unable to access visible property of Pivot Items class

To prevent the error, set the Sort for the field to Manual. For example:

With pf
.AutoSort xlManual, "Pivot Class"
.Orientation = xlColumnField

Geoff wrote:
Hi,

with the following code I get run-time error 1004 with the above description:

Set pt = ActiveSheet.PivotTables("Pivot_Table")
Set pf = pt.PivotFields("Pivot Class")

With pf
.Orientation = xlColumnField
.Position = 1
For Each pi In pf.PivotItems
If pi.Name = "#N/A" Or "1" Then
pi.Visible = False
Else: pi.Visible = True
End If
Next pi
End With

The error occurs at the line

pi.Visible = False

funnily enough when the test condition of the If statement has failed, i.e.
execution should have skipped this line.

Also, the Orientation property of the PivotField for some reason changes to
xlHidden, after it has been explicitly set to xlColumnField before entering
the If statement. I have a suspicion that this may be behind it, but I don't
know of a way to stop this particular property changing.

Any suggestions?

Thanks



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Unable to access visible property of Pivot Items class

Thanks very much Debra, this was exactly the solution needed. This of course
then helped me to discover the glaring error in my condition, where I asked
Excel to check whether "1" was true, rather than checking pi.Name = "1" :)

Thanks

"Debra Dalgleish" wrote:

To prevent the error, set the Sort for the field to Manual. For example:

With pf
.AutoSort xlManual, "Pivot Class"
.Orientation = xlColumnField

Geoff wrote:
Hi,

with the following code I get run-time error 1004 with the above description:

Set pt = ActiveSheet.PivotTables("Pivot_Table")
Set pf = pt.PivotFields("Pivot Class")

With pf
.Orientation = xlColumnField
.Position = 1
For Each pi In pf.PivotItems
If pi.Name = "#N/A" Or "1" Then
pi.Visible = False
Else: pi.Visible = True
End If
Next pi
End With

The error occurs at the line

pi.Visible = False

funnily enough when the test condition of the If statement has failed, i.e.
execution should have skipped this line.

Also, the Orientation property of the PivotField for some reason changes to
xlHidden, after it has been explicitly set to xlColumnField before entering
the If statement. I have a suspicion that this may be behind it, but I don't
know of a way to stop this particular property changing.

Any suggestions?

Thanks



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html


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
Unable to access visible property of Pivot Items class Geoff Excel Programming 0 May 20th 07 10:20 PM
Unable to set the visible property of the PivotItem class JimRWR Excel Programming 3 May 3rd 07 09:06 PM
"Unable to get Pivot Tables Property of Worksheet Class "Error [email protected] Excel Programming 2 April 30th 07 06:18 PM
Error:Unable to set the visible property of the PivotItem class. Holger Pietsch Excel Programming 2 August 16th 05 05:11 PM
Run-time error '1004' - Unable to set the Visible property of the Worksheet class Shalin Chopra Excel Programming 3 November 25th 03 08:38 PM


All times are GMT +1. The time now is 04:36 PM.

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

About Us

"It's about Microsoft Excel"