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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,746
Messages
6,126,641
Members
449,325
Latest member
Hardey6ix

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