SetSourcedata of pivotchart on a pivot table that changes

I am having troubles with a pivotchart that is based upon a pivottable that when refreshed can change size in terms of rows and columns. When recording a macro, the destination is hardcoded as follows:

Charts.Add
ActiveChart.ChartType = xlColumnStacked
ActiveChart.SetSourceData Source:=Sheets("CMR Count by Mgr & Type table"). _
Range("A1:BD20")
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:= _
"CMR Count by Mgr & Type chart"

where Range("A1:BD20") is a actually a pivottable created in a previous subroutine. Depending upon the data, the actual size of the pivottable may be different than what is in this code.

How do I dynamically create a pivottable that will have an unknown number of rows and columns and associate a pivotchart with the pivottable?

[865 byte] By [KC.M2Family] at [2007-12-23]
# 1

Since a pivot chart uses the entire pivot table (except subtotals and totals) as its source data, you need only define one cell in the pivot table, and the source data will expand to include the entire pivot table.

ActiveChart.SetSourceData Source:=Sheets("CMR Count by Mgr & Type table"). _
Range("A1")

- Jon
-
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_

JonPeltier at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...