Changing chartobject name VBA

dualhcsniatpac

Board Regular
Joined
Feb 18, 2009
Messages
126
Is there anyway that I can rename a chart object through VBA so it is easier to refer to them instead of "Chart1" and so on. Im guessing it is something you do when creating the chart.

Code:
ActiveSheet.ChartObjects("Chart 1")
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
So when I am in the process of writing my chart in VBA, for example 1 sheet has 4 charts, they will all use ChartObjects(1)??? Or will it change??

Thank you for the help Mike!
 
Upvote 0
Hi, Use the below for your requirement.

Dim sChtName As String
' unique name for chart object
sChtName = format(now,"yymmdd_hhmmss")
activesheet.chartobjects(activesheet.chartobjects.count).name = sChtname

Now you can reference the chart object using

ActiveSheet.ChartObjects(sChtname)

instead of

ActiveSheet.ChartObjects("Chart 1")
 
Upvote 0
So when I am in the process of writing my chart in VBA, for example 1 sheet has 4 charts, they will all use ChartObjects(1)??? Or will it change??

Thank you for the help Mike!

Each will use a different chart object so you will have ChartObjects(1),ChartObjects(2),ChartObjects(3),ChartObjects(4) on your sheet.
 
Upvote 0
When you are creating the chart in code, you can set the Name property of the chartobject using something like:
Code:
Dim cht as chart
set cht = charts.add
' various chart code
cht.Parent.Name = "your chartobject name here"
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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