Excel VBA PivotSelect

In the following example,

  • A list of levels are specified
  • Level unique names are quoted, followed by brackets.
  • At the before the closing bracket, qualifiers may be added
  • Data to include data for the level
  • Totals to include totals for the level
  • Only the last qualifier specified for a level is observed
  • Levels on the same axis union
  • Levels on opposing axis intersect
  • Each level is separated by a space
  • Within brackets, included member keys can be listed
  • , separates members in the list.
  • : acts as a range operator
  • Values are specified using a Values level.

Worksheets(1).PivotTables(1)..PivotSelect _
“‘[Date].[Calendar Year].[Calendar Year]'[” & _
“‘[Date].[Calendar Year].&[2011]’:'[Date].[Calendar Year].&[2012]'” & _
“;Data] ” & _
“‘[Date].[Calendar Year].[Calendar Year]'[” & _
“‘[Date].[Calendar Year].&[2014]’ ” & _
“] ” & _
“‘[Date].[Month Name].[Month Name]'[” & _
“‘[Date].[Month Name].&[January]’,” & _
“‘[Date].[Month Name].&[March]'” & _
“] ” & _
“‘[Geography].[Country Region Name].[Country Region Name]'[” & _
“‘[Geography].[Country Region Name].&[Australia]’,” & _
“‘[Geography].[Country Region Name].&[France]'” & _
“;Data;Total] ” & _
“Values[” & _
“‘[Measures].[Internet Total Sales]’,” & _
“‘[Measures].[Internet Total Units]'” & _
“] “, _
xlDataOnly