Microsoft Office Tutorials and References
In Depth Information
Using VBA to Display Arbitrary Data Labels on a Chart
Points(i).DataLabel.Text = DLRange(i)
This example, named data labels.xlsm , is available on the companion CD-ROM.
Figure 18-10 shows the chart after running the DataLabelsFromRange procedure and
specifying A2:A9 as the data range.
Figure 18-10: This XY chart has data labels, thanks to a VBA procedure.
A data label in a chart can also consist of a link to a cell. To modify the DataLabelsFromRange
procedure so it creates cell links, just change the statement within the For-Next loop to:
Cht.SeriesCollection(1).Points(i).DataLabel.Text = _
“=” & “’” & DLRange.Parent.Name & “’!” & _
The preceding procedure is rather crude and does very little error checking. In addition,
it only works with the first Series object. The Power Utility Pak add-in (which you can
obtain by using the coupon in the back of the topic) includes a much more
sophisticated chart data–labeling utility.