Skip to main content

Charts object

Table of contents
  1. Remarks
  2. Example

A collection of all the chart sheets in the specified or active workbook.

Remarks

Each chart sheet is represented by a Chart object. This does not include charts embedded on worksheets or dialog sheets. For information about embedded charts, see the Chart and ChartObject objects.

Example

Use the Charts property of the Workbook object to return the Charts collection. The following example prints all chart sheets in the active workbook.

Charts.PrintOut

Use the Add method of the ChartObjects object to create a new chart sheet and add it to the workbook. The following example adds a new chart sheet to the active workbook and places the new chart sheet immediately after the worksheet named Sheet1.

Charts.Add After:=Worksheets("Sheet1")

You can combine the Add method with the ChartWizard method of the Chart object to add a new chart that contains data from a worksheet. The following example adds a new line chart based on data in cells A1:A20 on the worksheet named Sheet1.

With Charts.Add
    .ChartWizard Source:=Worksheets("Sheet1").Range("A1:A20"), Gallery:=xlLine, Title:="February Data"
End With

Use Charts (index), where index is the chart-sheet index number or name, to return a single Chart object. The following example changes the color of series 1 on chart sheet 1 to red.

Charts(1).SeriesCollection(1).Format.Fill.ForeColor.RGB = rgbRed

The Sheets collection contains all the sheets in the workbook (both chart sheets and worksheets). Use Sheets (index), where index is the sheet name or number, to return a single sheet.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>