Problem changing pivot field

K

King

Hello-

I am trying to take selections from a ListBox (named Product_Codes)
and use those selections in a pivot table. As a first step I am
trying to deselect all items in a pivot field called "product_code"
but I keep getting an error. Here is my code (sorry if it posts
sloppy):

[vb]Private Sub Create_Report_Click()

Dim iCode As PivotItem
Dim PT As PivotTable

Set PT = Sheets("Network").PivotTables("PivotTable1")

Application.ScreenUpdating = False

' Clear all Product Codes from Pivot Field "product_code"

For Each iCode In PT.PivotFields("product_code").PivotItems
PT.PivotFields("product_code").PivotItems(iCode).Visible = False
'Getting error
here;
Next iCode '"Unable to get PivotItems Property of the
PivotField Class

Application.screendupdating = True

End Sub[/vb]

I know it is difficult without seeing the userform or file, but any
help is appreciated. Thanks!
 
A

Anya

Try putting iCode.Value in this loop:

For Each iCode In PT.PivotFields("product_code").PivotItems
PT.PivotFields("product_code").PivotItem
(iCode.Value).Visible = False
Next iCode
 
K

King

Didn't work;

Here is the code again with that change:

Private Sub Create_Report_Click()

Dim iCode As PivotItem
Dim PT As PivotTable
Dim i As Integer
Dim numProds As Integer

numProds = Product_Codes.ListCount

Set PT = Sheets("Network").PivotTables("PivotTable1")

Application.ScreenUpdating = False

' Clear all Product Codes from Pivot Field "product_code"

For Each iCode In PT.PivotFields("Prod Code").PivotItems

With Sheets("Network").PivotTables("PivotTable1").PivotFields("Prod
Code")
.PivotItems(iCode.Value).Visible = False
End With

Next iCode

End Sub

I also tried setting all to true in case it was a matter of needing to have
at least one selected. Thanks for your help.


Anya said:
Try putting iCode.Value in this loop:

For Each iCode In PT.PivotFields("product_code").PivotItems
PT.PivotFields("product_code").PivotItem
(iCode.Value).Visible = False
Next iCode
-----Original Message-----
Hello-

I am trying to take selections from a ListBox (named Product_Codes)
and use those selections in a pivot table. As a first step I am
trying to deselect all items in a pivot field called "product_code"
but I keep getting an error. Here is my code (sorry if it posts
sloppy):

[vb]Private Sub Create_Report_Click()

Dim iCode As PivotItem
Dim PT As PivotTable

Set PT = Sheets("Network").PivotTables("PivotTable1")

Application.ScreenUpdating = False

' Clear all Product Codes from Pivot Field "product_code"

For Each iCode In PT.PivotFields ("product_code").PivotItems
PT.PivotFields("product_code").PivotItems (iCode).Visible = False
'Gettin g error
here;
Next iCode '"Unable to get PivotItems Property of the
PivotField Class

Application.screendupdating = True

End Sub[/vb]

I know it is difficult without seeing the userform or file, but any
help is appreciated. Thanks!
.
 

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

Top