Hi All,
I am using Excel 2003 and I have a pivot table with about 50 pivot items that I need to iterate through, making each one visiible individually , then copy the pivot table and paste it into a new workbook and the move on to the next pivot item and do the same.
When I execute the code I get this error message:
Run-time error '1004'
Unable to set the Visible property of the Pivot Item class.
Which occurs when trying to run
PivotItems(i).Visible = True
Option Explicit
Sub PivotStockItems()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Country")
Dim i As Integer
For i = 2 To .PivotItems.Count
If .PivotItems(i).Visible = False Then
.PivotItems(i).Visible = True
.PivotItems(1).Visible = False
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
.PivotItems(1).Visible = True
.PivotItems(i).Visible = False
End If
Next i
End With
End Sub
i would appreciate any suggestions.
Thanks,
Trebormac
I am using Excel 2003 and I have a pivot table with about 50 pivot items that I need to iterate through, making each one visiible individually , then copy the pivot table and paste it into a new workbook and the move on to the next pivot item and do the same.
When I execute the code I get this error message:
Run-time error '1004'
Unable to set the Visible property of the Pivot Item class.
Which occurs when trying to run
PivotItems(i).Visible = True
Option Explicit
Sub PivotStockItems()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Country")
Dim i As Integer
For i = 2 To .PivotItems.Count
If .PivotItems(i).Visible = False Then
.PivotItems(i).Visible = True
.PivotItems(1).Visible = False
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
.PivotItems(1).Visible = True
.PivotItems(i).Visible = False
End If
Next i
End With
End Sub
i would appreciate any suggestions.
Thanks,
Trebormac