DutchBaron
New Member
- Joined
- Jul 27, 2012
- Messages
- 6
Hi guys,
I've got a problem.
I'm working with a database and periodic reports that need to be run. I've set up a pivot table that can be updated monthly with departments in column labels and order data on row labels. What I'm looking to achieve is generating output specific to users. That means: a single excel file tailored to a department.
What I've gotten so far:
However, this loop yields an error: Run-time error '1004': unable to get the PivotItems property of the PivotField class. Can you guys help me adjusting this code?
Thanks for all input!
I've got a problem.
I'm working with a database and periodic reports that need to be run. I've set up a pivot table that can be updated monthly with departments in column labels and order data on row labels. What I'm looking to achieve is generating output specific to users. That means: a single excel file tailored to a department.
What I've gotten so far:
Code:
Sub PivotLoop()
Dim PvTable As PivotTable
Dim PvField As PivotField
Dim PvItem As PivotItem
Dim PvItemL As PivotItem
Set PvTable = ActiveSheet.PivotTables("PivotTable2")
Set PvField = PvTable.PivotFields("Department")
For Each PvItem In PvField.PivotItems
For Each PvItemL In PvField.PivotItems
If PvItemL = PvItem Then
PvField.PivotItems(PvItemL).Visible = True 'Error occurs here
Else: PvField.PivotItems(PvItemL).Visible = False
End If
Next
' code to save file goes here
Next
End Sub
However, this loop yields an error: Run-time error '1004': unable to get the PivotItems property of the PivotField class. Can you guys help me adjusting this code?
Thanks for all input!