ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   naming charts (https://www.excelbanter.com/excel-programming/338218-naming-charts.html)

Tim[_39_]

naming charts
 
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



Andy Pope

naming charts
 
Hi Tim,

Hold the shift key and then select the chart object. You should get
white handles at the corners instead of the usual black. You can now use
the Name box, next to the formula bar, to change the chart name.

With code,

Activechart.parent.name = "MyChart"

Cheers
Andy

Tim wrote:
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Tushar Mehta

naming charts
 
For embedded charts you are better off naming the container that
contains the chart. Using the GUI, hold down SHIFT and click on a
chart. You will see that circles framing the selected object (which
happens to be called a chartobject).

Next, check the contents of the Name Box (extreme left of the formula
bar. If all the charts have default names it will contain something
like Chart n where n is a number. Click in the Name Box, enter your
desired name and complete the naming process with the ENTER key.

You can now refer to the chart in VBA as {sheet-reference}.ChartObjects
({name-used-above}).Chart

To do the same in VBA when you create a chart, it would depend on how
you created the chart and what, if any, variable you've used in the
process. I always use a variable that refers to the chart. So, I
would use aChart.Parent.Name="My name for the chartobject"

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , t_marsh@---take-
this-out-to-reply---atcentre.co.uk says...
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim




crazybass2

naming charts
 
Tim

From my basis knowledge of charts in a sheet they are named based on how
they are created. The first chart you create on a sheet will be named Chart1
then Chart2, and so on.

You can determine the name of a chart by right clicking on a whitespace area
of the chart and selecting "Chart Window." Once you know the name of the
chart you can refer to it as follows:

This will select the first chart created on sheet1. For the second Chart
created you would change the 1 to a 2 and so on


Sheet1.ChartObjects(1).select


Mike


"Tim" wrote:

Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim




Tim[_39_]

naming charts
 
superb! thanks for everybody's help here! its amazing i can have used
Excel for so long without ever realising something as apparently basic as
that!

"Andy Pope" wrote in message
...
Hi Tim,

Hold the shift key and then select the chart object. You should get
white handles at the corners instead of the usual black. You can now use
the Name box, next to the formula bar, to change the chart name.

With code,

Activechart.parent.name = "MyChart"

Cheers
Andy

Tim wrote:
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but

found no
reference to this topic)... if naming is not possible how would i go

about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info




Mariano B.

naming charts
 

Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings

--
Mariano



Andy Pope

naming charts
 
As the chart is embedded you need to use

ActiveChart.parent.name = "HourChart"

Cheers
Andy

Mariano B. wrote:
Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Mariano B.

naming charts
 
sorry, I forgot tu paste this code:


Function ChartExists(hoja As String, name As String) As Boolean
Dim C As ChartObject
On Error Resume Next
Set C = Sheets(hoja).ChartObjects(name)
If Err = 0 Then
ChartExists = True
Else
ChartExists = False
End If
End Function


--
Mariano



Mariano B.

naming charts
 

Thanks Andy!
I hadn't considered that.

--
Mariano


"Andy Pope" wrote:

As the chart is embedded you need to use

ActiveChart.parent.name = "HourChart"

Cheers
Andy

Mariano B. wrote:
Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



All times are GMT +1. The time now is 05:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com