excel - Using a Macro to reformat a PivotTable at every change -
i have pivottable reformats every time new filter set, or field collapsed/expanded. have built out macro reformats columns in way want, have had link button must clicked after pivot table change. prefer if macro ran upon change in pivottable, attempts automate have either generated error or no action whatsoever. have tried using "worksheet_change(byval target sheet)
" "worksheet_pivottableupdate(byval target pivottable)
" neither works. have assign specific pivottable number or sheet number them work? current code have entered in follows;
sub formatpivot() ' ' formatpivot macro ' columns("d:h").select selection.columnwidth = 17.56 activewindow.scrollcolumn = 3 activewindow.scrollcolumn = 2 cells.select selection.font .colorindex = xlautomatic .tintandshade = 0 end range("b3").select end sub private sub worksheet_pivottableupdate(byval target pivottable) call formatpivot end sub
use references cells on pivot sheet, not active sheet.
sub formatpivot() ' ' formatpivot macro ' ' dim pivot worksheet dim myrange range set pivot = thisworkbook.worksheets("thenameofthesheetwithpivot") set myrange = pivot.columns("d:h") myrange.columnwidth = 17.56 myrange.font .colorindex = xlautomatic .tintandshade = 0 end end sub private sub worksheet_pivottableupdate(byval target pivottable) call formatpivot end sub
Comments
Post a Comment