Excel Pivot Table issue setting a column to "Running Total" using VBA -
i using vba loop through pivot tables in order update values include new data (from external source) , update start , end dates groupings. code works...
for each pvt in ws.pivottables each pvtfld in pvt.rowfields rowlabel = pvtfld.name pvtfld.datarange.group start:=startdate, end:=enddate, by:=7, periods:=array(false, false, false, true, false, false, false) next pvtfld ... [trouble code go here, let me explain further] next pvt
the problem encountering upon refresh of "running totals" reset "no calculation.
recording macro helpful not useful other spreadsheets
' sets "total" column each pivot "running total" ws.pivottables("loepivot").pivotfields( _ "total planned loe") .calculation = xlrunningtotal .basefield = "moi" end
so, tried embed for each
this...
for each pvtcol in pvt.columnfields if pvtcol.name .name & "total" pvtcol.calculation = xlrunningtotal end if next pvtcol
this doesn't work though b/c column names equal string "values"
is there different method or property missing?
i ran same difficulty, found solution. after looking marco did found out set 'base field' wrong (right click on pivot > show values > running totals in > [shows base field]).
by adding .basefield
(e.g. .basefield = "week number") after .calculation
should able solve issue.
potentially link http://www.brainbell.com/tutorials/excel_vba/running_total.html.
Comments
Post a Comment