Pivot table filter item doesnt exist

paulnray

New Member
Joined
May 24, 2005
Messages
29
Hi wonder if anyone can help.

I have a macro that creates 28 workbooks and does pivot tables on each workbook but excludes one of the columns if it is exempt

So I have
A - Recorded
B - Expires This Month
C - Not Recorded
Exempt

Problem is not all of them have Exempt and when this happens it falls over. Is their anyway I can get it to ignore exempt if it doesnt exist.

My code looks like this

Regards

Paul

Code:
Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "'" & strSheetName & "'!" & strDataRange & "").CreatePivotTable TableDestination:="", _
        TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Care Group")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Cost Centre")
        .Orientation = xlRowField
        .Position = 2
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("IPR Recorded")
        .Orientation = xlColumnField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("IPR Recorded")
        .PivotItems("Exempt").Visible = False
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Assignment"), "Count of Assignment", xlCount
    Range("D13").Select
    ActiveSheet.PivotTables("PivotTable1").NullString = "0"
    ActiveWorkbook.ShowPivotTableFieldList = False

All help appreciated
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
One way:

Code:
    On Error Resume Next
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("IPR Recorded")
        .PivotItems("Exempt").Visible = False
    End With
    On Error GoTo 0
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

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