Name

pivotfield.AddPageItem(Item, [ClearList])

Synopsis

For OLAP pivot tables, selects an item in a page field.

Argument

Settings

Item

The name of the pivot item to select.

ClearList

True deselects all items from the page field before selecting the new one; False retains the current list of items.

To be able to select individual items in an OLAP page field, you must first select Select Multiple Items as shown in Figure 13-19. Use the CubeField object’s EnableMultiplePageItems property to select or deselect this option in code.

Enabling multiselect in OLAP page fields

Figure 13-19. Enabling multiselect in OLAP page fields

The following code selects a single item from the FoodMart Sales OLAP pivot table created in an earlier example:

Sub ViewSingleStore(  )
    Dim pt As PivotTable, cf As CubeField
    ' Uncomment this line to create OLAP pivot table.
    'CreateOLAPPivotTable
    ' Get OLAP pivot table.
    Set pt = Worksheets("FoodMart Sales").PivotTables(1)
    ' Get cube field
    Set cf = pt.CubeFields(pt.PageFields(1).Name)
    ' Enable multiselect.
    cf.EnableMultiplePageItems = True
    ' Select one store.
    pt.PageFields(1).AddPageItem "[Store].[All Stores].[USA].[CA].[Alameda]", True
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.