Chapter 18. Working with Charts

In This Chapter

Excel’s charting feature lets you create a wide variety of charts using data that’s stored in a worksheet. In this chapter, I discuss the following:

  • Essential background information on Excel charts

  • The difference between embedded charts and chart sheets

  • Understanding the Chart object model

  • Using methods other than the macro recorder to help you learn about Chart objects

  • Examples of common charting tasks that use VBA

  • Examples of more complex charting macros

  • Some interesting (and useful) chart-making tricks

Excel supports a wide variety of chart types, and you have a great deal of control over nearly every aspect of each chart. In Excel 2007, charts look better than ever.

About Charts

An Excel chart is simply packed with objects, each of which has its own properties and methods. Because of this, manipulating charts with Visual Basic for Applications (VBA) can be a bit of a challenge — and, unfortunately, the macro recorder isn’t much help in Excel 2007. In this chapter, I discuss the key concepts that you need to understand in order to write VBA code that generates or manipulates charts. The secret, as you’ll see, is a good understanding of the object hierarchy for charts. But first, a bit of background about Excel charts.

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 ...

Get Excel® 2007 Power Programming with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.