Pivot Table filter macro

kdmiller

New Member
Joined
Jun 1, 2015
Messages
1
First post on this board and hoping for help:

Using excel 2010 and have an excel spreadsheet that has two sheets,


  • data sheet which when refreshed goes off to a SharePoint and refreshes the data
  • Overview sheet which has a Pivot table of the data sheet

users add or modify a SharePoint form and one of the fields is "status", available options are New, final approval, manager approved, booked, claimed.

One of the columns in the data sheet is "status" and that is my first row Label in the pivot

I've created a very basic macro which when run switches to the data sheet and refreshes it, switches to the Overview sheet, refreshes the pivot and then sets the required checkbox's in the status filter, however if there is no status of the type I'm trying to set I get the following error

Run-time error '1004'
Unable to get the PivotItems property of the PivotField class

the VB is as follows:
Sheets("Data").Select
Range("F120").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("Overview").Select
Range("A6").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
With ActiveSheet.PivotTables("PivotTable2").PivotFields("status")
.PivotItems("new").Visible = True
.PivotItems("booked").Visible = True
.PivotItems("final approval").Visible = True
.PivotItems("done").Visible = True
.PivotItems("claimed").Visible = True
End With

what I'm looking for therefore is a way for each line of either checking to see if that status is available to set "True" or how to handle the error so that the macro ignores it.

any help much appreciated

Keith
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,203,046
Messages
6,053,191
Members
444,644
Latest member
keepontruckinc4

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