How to determine the chart name of a newly added chart

Andrew XJ

Board Regular
Joined
Feb 21, 2002
Messages
77
In one Spreadsheet, I use FOR loop to add several chart, the chart number varies. How can i extract the chart name of the newly added chart? Thx.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Is it necessary that ChartObjects(1) always refer to the chart added latestly? Seems not, So how to determine the name of the newly added chart?
Please help.....
 
Upvote 0
Right click on the chart and choose assign macro. The box that comes up will have the chart name in the top line. Cancel the box, unless of course you actually want to assign a macro to the chart.
 
Upvote 0
On 2002-02-27 18:41, Andrew XJ wrote:
In one Spreadsheet, I use FOR loop to add several chart, the chart number varies. How can i extract the chart name of the newly added chart? Thx.

If you set a chart object variable to be the new chart that has just been added, you can define the name yourself. For example:<pre>

Dim MyChart As Chart

For i = 1 To 5
Set MyChart = Application.Charts.Add
MyChart.Name = "Chart" & i
Next</pre>

In this example I'm just adding chart sheets rather inserting than chart objects onto sheets,
but the same principle applies.

_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-02-28 07:15
 
Upvote 0
These codes are for newly added codes. parts of my codes are as following:
ActiveSheet.ChartObjects("Chart 36").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy

ActiveWindow.Visible = False
Windows("Monthly Cpk Summary-PPT.xls").Activate
Range(Cells(10 * LoopP - 15, :cool:, Cells(10 * LoopP, 13)).Select
ActiveSheet.Paste

'Need to determine the chart name
ActiveSheet.ChartObjects("Chart " & LoopP + 52).Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Delete
ActiveChart.SeriesCollection(1).Delete

I use ActiveSheet.ChartObjects("Chart "& LoopP+52).Activate because i found that the latestly creatly chart is Chart 51. So in this case how can i name the chart?
No stuff such as "MyChart", right? so no MyChart.Name. Please enlighten.
 
Upvote 0
If the whole objective is to activate the last chart that was created, add this code to your project:<pre>
Public Sub ActivateLastChartAdded()

Dim chrt As ChartObject
Dim i As Integer

For Each chrt In ActiveSheet.ChartObjects
i = i + 1
Next

ActiveSheet.ChartObjects.Item(i).Activate

End Sub</pre>

Now to activate the last chart in your code, simply use<pre>
ActivateLastChartAdded</pre>

Instead of:<pre>

ActiveSheet.ChartObjects("Chart " & LoopP + 52).Activate</pre>


HTH
_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-02-28 10:10
This message was edited by Mark O'Brien on 2002-02-28 10:13
 
Upvote 0
An easier way to find the last chart and modify it is to use the count attribute, ie

ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Activate

to activate the last added chart or

ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Delete

to remove it.

Ex (remove all but the first two charts):

Do While ActiveSheet.ChartObjects.Count > 2
ActiveSheet.ChartObjects.Item(ActiveSheet.ChartObjects.Count).Delete
Loop
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,253
Members
448,556
Latest member
peterhess2002

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