1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Quản trị mạng >

Table 20-4. Values for the Subtotals Method's Index Parameter

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.72 MB, 490 trang )

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store City").Subtotals(2) = True

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store City").Subtotals(3) = True

We can also set the Subtotals property to an array of 12 Boolean values to set multiple subtotals.

For instance, the following code displays all subtotals:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store City"). _

Subtotals = Array(False, True, True, True, True, _

True, True, True, True, True, True, True)

Note that we set Automatic to False in this array, since if Automatic is set to True, then all

other values are set to False (thus providing a quick way to set all subtotals to False).

If this argument is omitted, the Subtotals method returns an array containing a Boolean value for

each subtotal.

20.8 The PivotCache Object

Pivot tables can manipulate the source data in a variety of ways, and this can require a great deal

of processing power. For maximum efficiency, the data for a pivot table is first stored in memory

in what is referred to as a pivot cache. The pivot table, itself, actually provides various views of

the pivot cache. This allows manipulation of the data without the need to access the original

source further which might, after all, be an external data source.

The PivotCache object represents a pivot table's cache. It is returned by the PivotCache method of

the PivotTable object. Let us take a look at some of the main properties and methods of the

PivotCache object.

20.8.1 Refreshing a Pivot Cache

The Refresh method refreshes both the pivot cache and the pivot table.

However, we can prevent a pivot table from being refreshed, either through the user interface (the

Refresh data menu item on the PivotTable menu) or through code, by setting the EnableRefresh

property to False.

The read-write Boolean RefreshOnFileOpen property is True if the PivotTable cache is

automatically updated each time the workbook is opened by the user. The default value is False.

Note that this property is ignored if the EnableRefresh property is set to False. Note also that the

PivotTable cache is not automatically refreshed when the workbook is opened through code, even

if RefreshOnFileOpen is True.

The RefreshDate property returns the date on which the pivot cache was last refreshed, and the

RefreshName property returns the name of the user who last refreshed the cache.

20.8.2 MemoryUsed Property

The read-only MemoryUsed property applies to either a PivotCache object or a PivotField object

and returns the amount of memory currently being used by the cache, in bytes.


20.8.3 OptimizeCache Property

Cache optimization is used with large or complex source data. It will slow the initial construction

of the cache. This read-write Boolean property can be used to set cache optimization.

Unfortunately, the precise consequences of cache optimization are not made clear in the

documentation, leaving us to use trial and error to decide whether it should be employed. Perhaps

the best strategy is to leave this property set to its default (False) unless performance seems to be

a problem.

20.8.4 RecordCount Property

This read-only property returns the number of records in the PivotTable cache.

20.8.5 SourceData Property

This property returns the data source for the PivotTable, as we discussed in the section on the

PivotTable object.

20.8.6 Sql Property

This read-write string property returns or sets the SQL query string used with an ODBC data


20.9 The PivotItem Object

A PivotItem is a unique value of a PivotField. To illustrate, consider the following code:

Dim pi As PivotItem

For Each pi In _

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store City").PivotItems

Debug.Print pi.Name


That code will print the list:




which contains the distinct Store City values from the Store City pivot field.

The PivotItems method of the PivotField object returns PivotItem objects. The syntax:


returns the collection of all PivotItem objects for that PivotField. The syntax:



can return a single PivotItem object or an array of PivotItem objects (by setting Index to an array

of indexes).

Table 20-5 shows the properties and methods of the PivotItem object. Let us take a look at some

of these members. Note that several of the members of the PivotField object also apply to the

PivotItem object.







Table 20-5. Members of the PivotItem Object













20.9.1 DataRange Property

This property returns a Range object representing the data area associated with the given

PivotItem. To illustrate, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type"). _


results in Figure 20-37.

Figure 20-37. DataRange for Store Type = Company

20.9.2 LabelRange Property

The LabelRange property returns a Range object that represents the label cells for the PivotItem.

Figure 20-38 illustrates the results of the code:

ActiveSheet.PivotTables("Sales&Trans"). _


PivotFields("Store Type"). _


Figure 20-38. LabelRange for Store Type = Company

20.9.3 IsCalculated Property

This property returns True if the pivot item is a calculated item. We discuss calculated items later

in the chapter.

20.9.4 Name, Value, and SourceName Properties

The read-write Name property returns or sets the name of the PivotItem. This is the value that

appears in the label for that item. The Value property is the same as the Name property.

The read-only SourceName property returns the name of the item in the original source data. This

may differ from the value of the Name property if the Name property has been changed.

20.9.5 Position Property

The Position property returns or sets the position of the pivot item. For instance, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type"). _


returns the number 2, since Franchise is the second pivot item in the pivot table (see Figure 20-10).

Moreover, we can reverse the positions of Company and Franchise by setting the Position of the

Franchise pivot item to 1, as follows:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type"). _

PivotItems("Franchise").Position = 1

20.9.6 RecordCount Property


Xem Thêm
Tải bản đầy đủ (.pdf) (490 trang)