How do you add name to a chart in Excel?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am trying to add names to 3 charts, all in the same sheet
But this code is giving runtime error


Worksheets("Analysis").Activat

With ActiveShee
.ChartObjects("Chart 1").Chart.Name = "A density
.ChartObjects("Chart 2").Name = "T- Distribution
.ChartObjects("Chart 3").Name = "R-Distribution

End Wit

Any help is appreciated
Thank
 
What error? And what line does the VBE highlight?

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
The first line is wrong: the Chart cannot be named. But the second and
third should work once you fix the first.

- Jon
 
No, even when I change the first line to

.ChartObjects("Chart 1").Name=" A Density"

it is not working. It is giving error

Run-time Error "1004" :
Unable to get the ChartObjects property of the Worksheet Class

----- Jon Peltier wrote: -----

The first line is wrong: the Chart cannot be named. But the second and
third should work once you fix the first.

- Jon
 
I changed the name of each chart manually( by slecting the chart and pressing SHIFT button) and I did the following modificatio

Private Sub ComboBox1_Change(

Worksheets("Graphical Analysis").Activat

With ActiveShee
' .ChartObjects("Chart 1").Name = "A density
' .ChartObjects("Chart 2").Name = "T-Distribution
' .ChartObjects("Chart 3").Name = "R-Distribution
.ChartObjects(Range("AY3").Value).BringToFron

End Wit

End Su
But its giving error 1004 on lin
.ChartObjects(Range("AY3").Value).BringToFron

If I remove the comments, then it is giving error 1004 on lin
..ChartObjects("Chart 1").Name = "A density

Why is this happening? Kindly help
Thank
Shilp

----- Tushar Mehta wrote: ----

What error? And what line does the VBE highlight

--
Regards

Tushar Mehta, MS MVP -- Exce
www.tushar-mehta.co
Excel, PowerPoint, and VBA add-ins, tutorial
Custom MS Office productivity solution
 
After changing the ChartObject's Name from "Chart 1" to "A Density",
it stands to reason you'll no longer be able to refer to it as "Chart 1".

You might have more luck refering to your ChartObjects via their index
into the ChartObjects collection. Like this,

ActiveSheet.ChartObjects(1).Name = "A density"
ActiveSheet.ChartObjects(2).Name = "T-Distribution"
ActiveSheet.ChartObjects(3).Name = "R-Distribution"

As for setting it's Z-Order, as long as cell AY3 on the Graphical
Analysis worksheet contains a valid name,(such as "T-Distribution")
your posted code should work just fine.

Regards,
Vic Eldridge
 
Back
Top