Rename chart name in VBA?

Calicat

Board Regular
Joined
Apr 18, 2003
Messages
144
I have a macro which creates a new Chart, and calls it Chart(1). I have the title, etc. already named in my macro, but I want to be able to rename the chart(1) tab in the workbook. The chart is NOT embedded in a spreadsheet.

In the VBA help, it mentions the name property, but the examples are not clear on how to use this in VBA for a chart. Any suggestions?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Something like

Cht.Name = "MyChart"

if you use an object variable for the chart, or this too:

ActiveChart.Name = "MyChart"

or this

ActiveSheet.Name = "MyChart"
 
Upvote 0
Yes, it worked with Activechart.name = "Name"

I was trying it under the 'With chart' portion of my code, with the .name type of syntax.

THANKS! SOLVED.
 
Upvote 0
Quick tack-on, it looks like you're trying to use an index with a chart object in a sheet. These should fire using indexes and names, without the chart being active:

Code:
Sheets(1).ChartObjects(1).Name = "test2"
Sheets(1).Shapes("test2").Name = "test3"
Sheets(1).Shapes(1).Name = "test1"
Sheets(1).ChartObjects("test1").Name = "test2"

Shapes is little more vague...
 
Upvote 0
Calicat said:
Yes, it worked with Activechart.name = "Name"

I was trying it under the 'With chart' portion of my code, with the .name type of syntax.

THANKS! SOLVED.

When a chart is on a worksheet the Name property applies to the ChartObject object which is the container for the Chart object. So:

Code:
With Chart
   .Parent.Name = "Name"
End With

should work.
 
Upvote 0
Andrew Poulsom said:
:oops: Better tell Nate too!

D'Oh! :oops: I swear I can read... :eek:

Well how's this not functional?

Code:
Charts(1).Name = "Test"

Looks like the OP was very close in the orginal post.
 
Upvote 0

Forum statistics

Threads
1,221,691
Messages
6,161,322
Members
451,696
Latest member
Senthil Murugan

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