David_Excel
New Member
- Joined
- May 7, 2013
- Messages
- 10
I've used this code before and it has worked fine, but now it won't create the graph and instead pulls up the pivot table filter pane and a pie chart for the entire pivot table, not just my selection. The range selection and deleted existing graphs seems to be working okay, the error is in the line highlighted bold.
Any help would be appreciated.
If ActiveSheet.ChartObjects.Count > 0 Then
ActiveSheet.ChartObjects.Delete
End If
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlPie
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=""London Profit By Product"""
ActiveChart.SeriesCollection(1).Values = "='Region Product'!$E$6:$E$15"
ActiveChart.SeriesCollection(1).XValues = "='Region Product'!$B$6:$B$15"
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels
Dim RngToCover As Range
Dim ChtOb As ChartObject
Set RngToCover = ActiveSheet.Range("f930")
Set ChtOb = ActiveChart.Parent
ChtOb.Height = RngToCover.Height ' resize
ChtOb.Width = RngToCover.Width ' resize
ChtOb.Top = RngToCover.Top ' reposition
ChtOb.Left = RngToCover.Left ' reposition
Any help would be appreciated.
If ActiveSheet.ChartObjects.Count > 0 Then
ActiveSheet.ChartObjects.Delete
End If
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlPie
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=""London Profit By Product"""
ActiveChart.SeriesCollection(1).Values = "='Region Product'!$E$6:$E$15"
ActiveChart.SeriesCollection(1).XValues = "='Region Product'!$B$6:$B$15"
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels
Dim RngToCover As Range
Dim ChtOb As ChartObject
Set RngToCover = ActiveSheet.Range("f930")
Set ChtOb = ActiveChart.Parent
ChtOb.Height = RngToCover.Height ' resize
ChtOb.Width = RngToCover.Width ' resize
ChtOb.Top = RngToCover.Top ' reposition
ChtOb.Left = RngToCover.Left ' reposition