garbour
01-25-2018, 03:09 PM
I have what I thought was to be a straightforward task to accomplish, but two days later I cannot figure out how to do this.
I've posted the simplest code of what I want to accomplish (for a single PivotTable). This code will turn off visibility of Name1-6 in Pivottable1. What I need the code to accomplish is to apply this filter to every PivotTable in my sheet (not workbook, only the activesheet), approximately 50 of them. Also, in there are instances where "Name2" or "Name4", etc. does not occur in a PivotTable. I would like the code to move on to the next name rather than throw an error.
Excel 2013
Sub filterPivot()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Memo")
.PivotItems("Name1").Visible = False
.PivotItems("Name2").Visible = False
.PivotItems("Name3").Visible = False
.PivotItems("Name4").Visible = False
.PivotItems("Name5").Visible = False
.PivotItems("Name6").Visible = False
End With
End Sub
Thanks to anyone who can help me out!
I've posted the simplest code of what I want to accomplish (for a single PivotTable). This code will turn off visibility of Name1-6 in Pivottable1. What I need the code to accomplish is to apply this filter to every PivotTable in my sheet (not workbook, only the activesheet), approximately 50 of them. Also, in there are instances where "Name2" or "Name4", etc. does not occur in a PivotTable. I would like the code to move on to the next name rather than throw an error.
Excel 2013
Sub filterPivot()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Memo")
.PivotItems("Name1").Visible = False
.PivotItems("Name2").Visible = False
.PivotItems("Name3").Visible = False
.PivotItems("Name4").Visible = False
.PivotItems("Name5").Visible = False
.PivotItems("Name6").Visible = False
End With
End Sub
Thanks to anyone who can help me out!