vba selecting multiple

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA - selecting multiple pivot items within a pivot field

VBA - selecting multiple pivot items within a pivot field

resolvedResolved · High Priority · Version 2010

Titus has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course

VBA - selecting multiple pivot items within a pivot field

Hi there

I have a pivot table that contains (amongst other things) various time periods that i need to update to return the correct data.

The time periods are split into years and quarters so for each time period i want, i need to select one of each.

This is fine for a single year/period, however on a number of occasions i need to report inception to date, i.e. all the periods up to the current (or specified) period.

I want to load all the years and periods into an array and then unload the array into the pivot, selecting all the periods, but i can't work out how to do so.

For example, one lines of the code i am using looks like this:

With ActiveSheet.PivotTables("PivotTable1").PivotFields("[Accounting Period].[Accounting Period]")
.AddPageItem "[Accounting Period].[Accounting Period].[Acct Year].&[" & FinancialYear & "].&[Qtr " & Quarter & "]"
End With

where FinancialYear is a variable and Quarter is also a variable. This will select one period only. I want to cycle through all available periods from, say, 2008.

Any help much appreciated.

Thanks

Titus

Edited on Fri 24 Jan 2014, 10:57

RE: VBA - selecting multiple pivot items within a pivot field

I have managed to get this to work for one of my connections using VisibleItemsList and an array, however another of my connections (OLAP) shows the above syntax when using the macro recorder and i can't get this to work with VisibleItemsList.

How does the .AddPageItem property work differently to the VisibleItemsList?

Many thanks

Titus

RE: VBA - selecting multiple pivot items within a pivot field

Hi Titus

Thanks for getting in touch. I confess my experience at hooking up PivotTables to an OLAP cube with VBA is brief, so I had to research your question.

Here are the Microsoft MSDN articles on the subjects:

http://msdn.microsoft.com/en-us/library/office/bb242470 (v=office.12).aspx

http://msdn.microsoft.com/en-us/library/office/ff838994.aspx

VisibleItemsList acts a bit like a filter (literally, "what is visible?"). AddPageItem adds new page items to the the Table. Page Items are like group filters for PivotTables and Excel now refers to them as 'Report' filters.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Tue 4 Feb 2014: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Transpose text

You can transpose any range of cells, turning the columns into rows and the rows into columns. Just follow these steps:

Select the range.

Click the Copy button on the Standard toolbar to copy it to the Clipboard.

Select a cell outside of the range you copied.

Select Paste Special from the Edit menu.

In the Paste Special dialog box, click Transpose, then OK.

View all Excel hints and tips


Server loaded in 0.08 secs.