Expand only those pivot items with more than one entry (Excel VBA) -
ok, trying have excel vba code go through pivot table , expand out entries in last row field don't have 1 entry in them. default, last row field collapsed.
what have far:
sub test() activesheet.pivottables("objsummarypt") dim pvtitem4, pvtitem5 pivotitem each pvtitem4 in .rowfields("object code grouping").pivotitems each pvtitem5 in .rowfields("contract & contract title").pivotitems if pvtitem5.name <> "non-contract" , pvtitem4.recordcount > 0 , pvtitem5.recordcount > 0 .pivotfields("object code grouping").pivotitems(pvtitem4.name).showdetail = true end if next pvtitem5 next pvtitem4 end end sub
this expands many of them, because isn't cross-referencing if there pvtitem5s in pvtitem4 have records, , not figuring out syntax so.
i recognize single entries aren't listed "non-contract" shown , don't take issue that; fine happen. want fewer false positives getting now.
found solution:
sub test() activesheet.pivottables("table") .pivotfields("cat6").pivotitems("testobject").visible = false dim pvtitem4, pvtitem5 pivotitem each pvtitem4 in .rowfields("cat5").pivotitems on error resume next if pvtitem4.datarange.column = null goto pvt4 .pivotfields("cat5").pivotitems(pvtitem4.name).showdetail = true pvt4: next pvtitem4 .pivotfields("cat6").pivotitems("testobject").visible = true end end sub
it works filtering out don't want expanded, determining other categories still visible in pivot table , expanding them, unfiltering.
Comments
Post a Comment