Thank you
Seth Clark
The following code creates labels in a chart from the text in the range
B4:G4. The range has 6 entries, corresponding to the number of x values in
the chart. The code works with an XY chart as well as other types of charts.
The code is taken from "Excel 2000 VBA Programmer's Reference", written by
myself and Stephen Bullen:
Sub AddDataLabels()
Dim SalesSeries As Series
Dim pts As Points
Dim pt As Point
Dim rng As Range
Dim i As Integer
Set rng = Range("B4:G4")
Set SalesSeries = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
SalesSeries.HasDataLabels = True
Set pts = SalesSeries.Points
For Each pt In pts
i = i + 1
pt.DataLabel.Text = "=" & rng.Cells(i).Address _
(RowAbsolute:=True, _
ColumnAbsolute:=True, _
ReferenceStyle:=xlR1C1, _
External:=True)
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
End Sub
This code links the data labels to the worksheet text, and the labels
automatically update if the cell values change. If you want to assign fixed
labels to the data points, change the For...Next loop to:
For Each pt In pts
i = i + 1
pt.DataLabel.Text = rng.Cells(i).Value
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
HTH,
John Green - Excel MVP
Sydney
Australia
In article <7lnve5$ajl$1...@solaris.cc.vt.edu>, Seth Clark wrote:
> From: "Seth Clark" <scl...@vt.edu>
> Newsgroups: microsoft.public.excel.programming
> Subject: how to add label to a point
> Date: Sun, 4 Jul 1999 11:40:38 -0400