Pivot Chart with VBA

TamirBasin

New Member
Joined
Apr 11, 2017
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Hello,

I recorded then altered the following code to create a pivot chart:

Code:
Sub CreatePivotChart()
    
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlColumnStacked
    ActiveChart.SetSourceData Source:=Sheets("PivRetained").Range("A3:F34")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="PivRetained"
    ActiveChart.Name = "Active Hires By Performance 2015" ' Here I get the error

End Sub

I get an error when I try to give the chart a name.

where is my mistake?

Thank you,
Tamir
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello Tamir,

Are you trying to change the chart name? or the displayed title ON the chart?

Caleeco
 
Upvote 0
Provided you have one chart on the sheet, this will do:
Code:
Sub PC_Name()    ActiveSheet.ChartObjects(1).Name = "Active Hires By Performance 2015"
End Sub

If you have more than one sheet, you would just need to pull the chart name of the newly created chart and adjust code accordingly.

Cheers
Caleeco
 
Upvote 0
I do have more than one chart on the sheet.
How do I assign a name to the chart that was just created?
See please this code:
What should I do to fix it?
Sub CreatePivotChart()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnStacked
ActiveChart.SetSourceData Source:=Sheets("PivRetained").Range("A3:F34")
ActiveChart.Name = "Active Hires By Performance 2015" ' Here I get the error
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top