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 normally holds a single chart.

Most charts are created manually by using the commands in the Insert' * Charts group. But you can also create charts by using VBA. And, of course, you can use VBA to modify existing charts.

Tip The fastest way to create a chart is to select your data and then press Alt+F1. Excel creates an embedded chart and uses the default chart type. To create a new default chart on a chart sheet, select the data and press F11.

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.

Note As you 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