Pivot Table Filtering

speth

New Member
Joined
Feb 18, 2013
Messages
27
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....

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?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Doesnt seem anything wrong with the code. Check spelling etc. Record the action and see if yours looks like the recording.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top