vba - Appy If statement in the pivot filter -


enter image description here

in this, not time, have option 12l or 03a when pull report. how apply if statement filter (deselect) when these options available.

with activesheet.pivottables("pivottable1").pivotfields("purchasing group")     .orientation = xlpagefield     .position = 1 end activesheet.pivottables("pivottable1").pivotfields("item").currentpage = "10" activesheet.pivottables("pivottable1").pivotfields("purchasing group"). _     currentpage = "(all)" activesheet.pivottables("pivottable1").pivotfields("purchasing group")     .pivotitems("03a").visible = false     .pivotitems("12l").visible = false end activesheet.pivottables("pivottable1").pivotfields("purchasing group"). _     enablemultiplepageitems = true range("a7").select activesheet.pivottables("pivottable1").innerdetail = "contract" selection.showdetail = true activesheet.pivottables("pivottable1").pivotcache.refresh end sub 

i assume this

with activesheet.pivottables("pivottable1").pivotfields("purchasing group")     .pivotitems("03a").visible = false     .pivotitems("12l").visible = false end 

generates error when "03a" , "12l" not available. can add on error resume next.

on error resume next 'in case of error, go next line activesheet.pivottables("pivottable1").pivotfields("purchasing group")     .pivotitems("03a").visible = false     .pivotitems("12l").visible = false end on error goto 0 'disable enabled error handler 

Comments