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 )
The ErrorString property can be used to set the string that is displayed in cells that contain errors
when DisplayErrorString is True. (The default value is an empty string.)
22.214.171.124 Null-related properties
When the DisplayNullString property is True, the PivotTable displays a custom string in cells
that contain null values. (The default value is True.)
The NullString property can be used to set the custom string for such cells. (The default value is
an empty string.)
126.96.36.199 EnableDrillDown property
One of the features of a PivotTable is the DrillDown feature. To illustrate, if we double-click on a
data cell, such as cell D5 in the pivot table of Figure 20-10, Excel will create a new worksheet, as
shown in Figure 20-22. This worksheet shows the original source rows that contribute to the value
in the double-clicked cell D5. (Note that the rows are complete, although the Sales column does
not contribute to cell D5.)
Figure 20-22. Illustrating DrillDown
By now you have probably guessed that the read-write Boolean property EnableDrillDown is used
to enable or to disable this feature for the pivot table.
188.8.131.52 Formatting properties and methods
The read-write HasAutoFormat property is True (its default value) if the PivotTable is
automatically formatted when it is refreshed or when some of its fields are moved.
The labels for the rows, columns, subtotals, and totals in Figure 20-6 are not merged with adjacent
blank cells. (The borders are adjusted so it may appear so, however.) To merge the labels with
adjacent blank cells, we can set the MergeLabels property to True.
The read-write PreserveFormatting property is True (its default value) if PivotTable formatting is
preserved when the PivotTable is refreshed or recalculated by operations such as pivoting, sorting,
or changing page-field items.
The TableStyle property returns or sets the style name (as a string) used in the PivotTable body.
The default value is a null string, so no style is applied.
184.108.40.206 Refreshing a pivot table
When the ManualUpdate property is True, the PivotTable is recalculated only at the user's
request. The default value is False.
The RefreshTable method refreshes the PivotTable from the original source data. The method
returns True if it is successful.
The RefreshDate property returns the date on which the PivotTable or pivot cache was last
refreshed. It is read-only.
The RefreshName property returns the user name of the person who last refreshed the PivotTable
data or pivot cache.
220.127.116.11 PageField-related properties
As discussed earlier in the chapter, the PageFieldOrder property returns or sets the order in which
page fields are added to the PivotTable layout. It can be one of the following XlOrder constants:
xlDownThenOver or xlOverThenDown. The default constant is xlDownThenOver.
Recall also that the PageFieldWrapCount property returns or sets the number of PivotTable page
fields in each column or row.
The PageFieldStyle property returns or sets the style used in the page field area.
18.104.22.168 Name property
This property returns or sets the name of the pivot table as a string.
22.214.171.124 SaveData property (R/W Boolean)
When this property is True, its default value, data for the PivotTable is saved with the workbook.
If it is False, only the PivotTable definition is saved.
126.96.36.199 ShowPages method
This method creates a new PivotTable for each item in the specified page field. Each new
PivotTable is created on a new worksheet. The syntax is:
For instance, if we apply this method to the pivot table in Figure 20-10 with the code:
we will get two new worksheets. One worksheet, named 1997, will contain the original pivot table,
but with the Year page field set to 1997. The other worksheet will contain the same pivot table
with the Year field set to 1998. (We can still change the Year field on any of the pivot tables. In
other words, each pivot table contains the data for all of the Year field values.)
188.8.131.52 SourceData property
This read-only property returns the data source for the PivotTable. For instance, when that source
is a single Excel worksheet, the SourceData method returns a string describing the source range.
returns the string:
20.6 Children of the PivotTable Object
The children of the PivotTable object are shown in Figure 20-23.
Figure 20-23. Children of the PivotTable object
20.7 The PivotField Object
The properties and methods of the PivotField object are shown in Table 20-3.
Table 20-3. Members of the PivotField Object
Let us take a look at some of these members.
20.7.1 AutoShow-Related Members
The AutoShow method is used to restrict the display of pivot items for a given pivot field. The
PivotFieldObject.AutoShow(Type, Range, Count, Field)
All parameters are required for this method.
The Type parameter has two possible values: xlAutomatic activates the remaining parameters
and, thereby, causes the restrictions to take effect, and xlManual disables the remaining
parameters and causes Excel to remove any restrictions caused by a previous call to this method
with Type equal to xlAutomatic.
The other parameters can be described by the following sentence: restrict pivot items to the top
(Range =xlTop) or bottom (Range =xlBottom) Count pivot items based on the value in
pivot field Field.
Thus, for instance, referring to Figure 20-10, the code:
PivotFields("Store Type").AutoShow _
xlAutomatic, xlTop, 1, "Sale"
shows the top (Range =xlTop and Count=1) Store Type based on the value of Sale. The result
is shown in Figure 20-24.