Peltier Technical Services, Inc.
 

Excel Chart Add-Ins | Training | Charts and Tutorials | Peltier Tech Blog


Peltier Tech Charts for Excel 3.0

 

Naming an Excel Chart

A common question people have is "How can I name an Excel chart?" When using VBA, you can activate a chart by name, but charts just get a default name like "Chart 3" or "Chart 88", in the order in which they are created. A recorded macro will capture that sequential name, but it's no good when you want to run the macro on another chart. Here are some techniques for naming charts.

Chart Sheets

A chart sheet has a name just like any other sheet. You name the sheet as follows.

Manually - Existing Chart Sheet:

Select the sheet. Double click on the sheet tab, type whatever name you want, and press Enter.

VBA - Active Chart Sheet:
ActiveChart.Name = "Name of this Chart"
VBA - Any Existing Chart Sheet:
ActiveWorkbook.Charts(3).Name = "Name of this Chart"

or...

ActiveWorkbook.Charts("Old Chart Name").Name = "Name of this Chart"
VBA - While Creating a New Chart:
Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:G14")
ActiveChart.Name = "Name of this Chart"

Embedded Charts

An embedded chart has no name property; the parent Chart Object has the name. You can name an embedded chart's parent chart object this way:

Manually - Existing Chart:

Select a cell. Hold Shift or Ctrl while clicking on the chart. The chart has white handles, not black (handles are those little squares on the corners and midpoints of the edges).


Chart is selected: note black handles.


Chart Object is selected in Excel 97 or 2000: note square white handles.


Chart Object is selected in Excel XP or later: note circular white handles.

Click in the Name Box (above the top left visible cell, to the left of the Formula Bar), where it probably says something like "Chart 3", and type whatever name you want, and press Enter.


Name Box, with chart name in red for emphasis.

VBA - Active Chart:
ActiveChart.Parent.Name = "Name of this Chart"
VBA - Any Existing Chart:
ActiveSheet.ChartObjects(3).Name = "Name of this Chart"

or...

ActiveSheet.ChartObjects("Old Chart Name").Name = "Name of this Chart"
VBA - While Creating a New Chart:

If you're adding a chart (sheet) then locating it on a worksheet:

Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:G14")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
ActiveChart.Parent.Name = "Name of this Chart"

If you're adding an embedded chart to a worksheet:

With ActiveSheet.ChartObjects.Add _
        (Left:=100, Width:=375, Top:=75, Height:=225)
    With .Chart
        .ChartType = xlXYScatterLines
        .SetSourceData Source:=Sheets("Sheet1").Range("A3:G14")
        .Parent.Name = "Name of this Chart"
    End With
End With
 

Peltier Tech Charts for Excel 3.0


Peltier Technical Services, Inc.

Excel Chart Add-Ins | Training | Charts and Tutorials | PTS Blog

Peltier Technical Services, Inc., Copyright © 2017. All rights reserved.
You may link to this article or portions of it on your site, but copying is prohibited without permission of Peltier Technical Services.

Microsoft Most Valuable Professional

Microsoft Most Valuable Professional

My MVP Profile