Microsoft Office Tutorials and References
In Depth Information
Troubleshooting
How Can I Determine If a Chart Has Been Activated?
A macro can manipulate an active chart, which has been selected by the user. For example,
a macro might change the chart type, apply colors, or change the font size. The question is,
how can you determine using VBA code whether the user has actually selected the chart?
The chart could be selected by activating the chart sheet or activating an embedded chart
by clicking it. If the chart that needs to be activated is on a chart sheet, you can use the
following line of code to determine if it has been selected:
TypeName(Selection) = “Chart”
However, if the chart is an embedded object, the actual selection would be an object within
the chart. For example, the object could be a Series object or a ChartTitle object. The
ChartIsSelected function returns True if a chart sheet or an embedded chart is activated
and False if a chart is not activated. The following function determines if the ActiveChart
object is Nothing . If it equals Nothing , the chart is not activated.
Private Function ChartIsSelected() As Boolean
ChartIsSelected = Not ActiveChart Is Nothing
End Function
Modifying a Chart’s Data Series
A chart consists of any number of series, and the data used in each series is determined by the
range references in its SERIES formula. When a series is selected in the chart, the SERIES
formula is displayed in the formula bar. In some cases, using range names in the SERIES for­
mulas in a chart can simplify things when you need to change the chart’s source data. For
example, consider the following SERIES formula:
=SERIES(,Sheet1!$A$1:$A$6,Sheet1!$B$1:$B$6,1)
You can define range names for the ranges and then edit the SERIES formula so that it uses
the range names instead of the range references. For example, if you have two ranges that are
named Categories and Data you can modify the formula to
=SERIES(,Sheet1!Categories,Sheet1!Data,1)
Note This formula might change when you type it in the formula bar. For example,
Sheet1 might evaluate to the name of the workbook, producing an argument such as
Products.xls!Categories .
Search JabSto ::




Custom Search