excel - Recorded "Macro" updates Pivot table's filter, where VBA script does not -


my final end goal give function year , based on year, set filter of "years" in pivot table. if record "macro" of myself doing (manual filtering, filtering none-the-less), can run "macro" without issues. if take exact same code + , error catcher (that doesn't catch errors) , return number (nothing calculated on number), however, , put in vba function, fails.

here "macro"

sub blank()     activesheet.pivottables("tmed_ptable").pivotfields("years")         = 2 .pivotitems.count             .pivotitems(i).visible = false         next     end end sub 

and here vba code

function updatepivot(tmedyear integer) integer     on error goto errorout         activesheet.pivottables("tmed_ptable").pivotfields("years")                 = 2 .pivotitems.count                     .pivotitems(i).visible = true                 next         end         goto endout     errorout:         msgbox "error: " & err & "(" & error(err) & ")"     endout:         updatepivot = tmedyear     end function 

note have scaled vba code way in attempting trouble shoot out, vba code not work. either there no change other outputting year or if executes, pivot table not filtered data removed.

i using excel 2010.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -