VBA to Rename a Pie Chart that I keep erasing and creating

salvamothe

New Member
Joined
Jun 22, 2011
Messages
2
Dear all,

I have a macro that creates a chart. In the macro I have all the actions to edit the chart, insert the source, etc. The only part missing is renaming the Chart.
I want to rename the chart, because I keep on creating charts and deleting them on my routine and afterwards I would like to export the specific charts to powerpoint.

Here is the text that I'm using that lacks the RENAME part:

Sub Charts()
Sheets("Dashboard").Select
With ActiveSheet.ChartObjects.Add _
(Left:=100, Width:=300, Top:=75, Height:=200)
.Chart.SetSourceData Source:=Sheets("DB1.2").Range("PieChart")
.Chart.ChartType = xl3DPieExploded
.Chart.ChartTitle.Select
With Selection.Format.TextFrame2.TextRange.Font
.NameComplexScript = "AdiHaus"
.NameFarEast = "AdiHaus"
.Name = "AdiHaus"
End With
Selection.Format.TextFrame2.TextRange.Font.Size = 14
Selection.Left = 111.277
Selection.Top = -5
.Chart.Legend.Select
Selection.Height = 44.994
Selection.Top = 179.105
Selection.Left = -9.93
Selection.Width = 378.93
.Chart.PlotArea.Select
Selection.Left = -13
Selection.Width = 499
Selection.Height = 446.588
Selection.Top = 13
End With
End With
End Sub

I've tried the commands:
.Chart.Name = "NEW NAME"

or

ActiveChart.Parent.Name = "NEW NAME"

or

ActiveSheet.ChartObjects(1).Name = "NEW NAME"

BUT THEY DON't WORK.

Thanks a ton!!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi!

I've just found out how to solve it. As simple as:

Sheets("Sheetname").ChartObjects(1).Name = "PieChart1"

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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