Pivotfield question

flipcube

Board Regular
Joined
Aug 29, 2011
Messages
134
Hi All,

I have a financial table from which I created various pivot tables based on Fiscal Month. The table has columns labeled "Jan-10", "Feb-11" etc...

The Pivot Table has to show a rolling 3 months of actuals and 9 months of forecasted data. How do I make .Pivotfields dynamic so that it retrieves the correct data based on Fiscal month and year without hard coding as in the example below?


ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Dec-10"), "Dec" & " " & Year(Date) - 1, xlCount

Thanks
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Sorry if the above is confusing...

here's what I am looking to do...hopefully.

below I created the variable Dec, as a string, how do i code pivotfields so that it uses the variable I created?

If FiscalMonth = "January" Then
month = "Dec"
Fyear = Year(Date) - 1
Dec = month & Fyear

ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(), "Dec" & " " & Year(Date) - 1, xlCount

My source data has multiple Decembers (Dec-10, Dec-11, Dec-12 etc...). So in Fiscal Jan 2012, I would like the PT to show Dec 2011 data. if I hard code "Dec-10" into pivotfield I will always be displaying Dec 2010 data.

can this be done?

thanks for the help
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top