I'm having trouble filtering what's in a pivot table using VBA. I have a large pivot table, but for sake of brevity, the attached sample is essentially the same thing.
In this sample, I'm getting kicked back with a 1004 error that it can't find the referenced PivotField. Here's the code....
Here's the data that's sent to the pivot table. The VBA is running after the table has been created (Sheet2).
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Bob[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Jim[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Sam[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Bill[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Ted[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Amy[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Becca[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Josh[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Any suggestions?
In this sample, I'm getting kicked back with a 1004 error that it can't find the referenced PivotField. Here's the code....
Code:
Sub PIVOT_TEST()
Sheets("Sheet2").PivotTables("PivotTable2").PivotFields("Number")PivotItem("4").Visible = False
End Sub
Here's the data that's sent to the pivot table. The VBA is running after the table has been created (Sheet2).
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Number[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Bob[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Jim[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Sam[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Bill[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Ted[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Amy[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Becca[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Josh[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Any suggestions?