Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The method that you use to remove a data series from being displayed on a PivotChart depends on the layout of the PivotChart. If your PivotChart contains more than one data series, then you must hide, rather than remove, the data series that you do not want displayed on the PivotChart. To do this, set the
Visible property of the
PivotItem object that you want to hide to
False. The following line of code illustrates how to do this:
ActiveChart.PivotLayout.PivotFields("Year").PivotItems("1996") _
.Visible = False
If your PivotChart contains only one data series, then set the
Orientation property of the
PivotField object that you want to hide to
xlHidden. The following line of code illustrates how to do this:
ActiveChart.PivotLayout.PivotFields("Sum of Sales").Orientation = xlHidden
NOTE: The PivotChart and the related PivotTable report will be empty after Excel executes this line of code.
The following sample code illustrates how to detect whether or not the current chart is a PivotChart.
If ActiveChart.PivotLayout Is Nothing Then
MsgBox "This is a normal chart."
Else
MsgBox "This is a PivotChart."
End If