Chart locations

In Excel, a chart can be located in either of two places within a workbook:

♦ As an embedded object on a worksheet: A worksheet can contain any number of embedded charts.

♦ In a separate chart sheet: A chart sheet holds a single chart.

As I discuss later in this chapter, you can also store embedded charts on a chart sheet. See "Storing multiple charts on a chart sheet."

Most charts are created manually, by using the Chart Wizard. But you can also create charts by using VBA. And, of course, you can use VBA to modify existing charts.

The fastest way to create a chart on a new sheet is to select your data and then press F11. Excel creates a new chart sheet and uses the default chart type.

A key concept when working with charts is the active chart —that is, the chart that's currently selected. When the user clicks an embedded chart or activates a chart sheet, a Chart object is activated. In VBA, the ActiveChart property returns the activated Chart object (if any). You can write code to work with this Chart object, much like you can write code to work with the Workbook object returned by the ActiveWorkbook property.

Here's an example: If a chart is activated, the following statement will display the Name property for the Chart object:

MsgBox ActiveChart.Name

If a chart is not activated, the preceding statement generates an error.

As you'll see later in this chapter, it's not necessary to activate a chart in order to manipulate it with VBA.

0 0

Post a comment