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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,834
Messages
5,855,905
Members
431,772
Latest member
dannyboi1

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
Top