VBA Months in Pivot Table

Analyze_This

Board Regular
Joined
Oct 29, 2008
Messages
122
Hey guys! I'm having a problem writing code that will allow for a range of months in a pivot table. First, here's the code for Jan-2010 through June-2010:

Code:
ActiveSheet.PivotTables("PivotTable8").PivotFields( _
        "[Dim Month].[Month ID].[Month ID]").VisibleItemsList = Array( _
        "[Dim Month].[Month ID].&[201001]", "[Dim Month].[Month ID].&[201002]", _
        "[Dim Month].[Month ID].&[201003]", "[Dim Month].[Month ID].&[201004]", _
        "[Dim Month].[Month ID].&[201005]", "[Dim Month].[Month ID].&[201006]")

This is connected to a data cube and it's how I have to filter the months. So If I want to add a month, I'd need to add another "[Dim Month].[Month ID]&[YearMonth]".

Is there a way that I can automate this with VBA so that it filters month from Jan to Current Month minus 1?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,218,809
Messages
6,144,607
Members
450,559
Latest member
kwenda farai

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