excel vba - Error '1004': Unable to set the Visible property of the PivotItem class -


i got below code here: looping through report filters change visibility doesn't work solution marked working. after modifying according need, this:

with pt.pivotfields(6)     .clearallfilters      if .pivotitems.count > 0          'goofy necessary         set firstpi = .pivotitems(1)          each pi in .pivotitems              if firstpi.visible = false                 firstpi.visible = true             end if               'don't loop through firstpi             if pi.value <> firstpi.value                 itemvalue = pt.getpivotdata("[measures].[nr of cancelled]", "[characteristics].[reason]", pi.name).value                  rw = rw + 1                 nwsheet.cells(rw, 1).value = pi.name                 nwsheet.cells(rw, 2).value = pi.visible                 if itemvalue < 2000                     if pi.visible = true                         pi.visible = false 'error here                     end if                 else                     msgbox pi.value                     if pi.visible = false                         pi.visible = true 'error here                     end if                 end if             end if         next                'finally perform check on first pivot item               if firstpi > 2000                   firstpi.visible = true               else                   firstpi.visible = false               end if            end if     end 

i see whole code working fine , i'm facing error lines pi.visible = true or pi.visible = false

i'm not sure i've done wrong code not work.

when searching internet soltuion, came across link: https://support.microsoft.com/en-us/kb/114822 ms mentioned only contiguous items in pivottable field can hidden. mean items in table not contiguous? can me? i'm lost here.

i didn't find solution error. found way achieve task. used array store items hide , items visible can call either hiddenitemslist or visibleitemslist:

    each pvtitem in pt.pivotfields(6).pivotitems         on error goto skipreason         itemvalue = pt.getpivotdata("[measures].[cancelled]", "[characteristics].[reason]", pvtitem.name).value         if itemvalue < 2000             hiddenreasons(hiddencount) = pvtitem.name             hiddencount = hiddencount + 1         else             visiblereasons(visiblecount) = pvtitem.name             visiblecount = visiblecount + 1         end if  sheets("cancels").pivottables("cancels").pivotfields( _     "[characteristics].[reason].[reason]" _     ).visibleitemslist = array(visiblereasons()) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -