Microsoft Office Tutorials and References
In Depth Information
Example 21-14. The cmdCancel and cmdSetLabels Click Events
' Get the labels range
Set rngLabels = Range(reditLabels.Value)
If rngLabels Is Nothing Then
MsgBox "You must select a range of cells equal in number to " &
_
"the number of data points in the series.", vbInformation
Exit Sub
End If
' Check counts
If cPoints <> rngLabels.Count Then
MsgBox "The number of label cells (" & rngLabels.Count & _
") does not equal the number of data points (" & cPoints & _
") in the selected series.", vbInformation
Exit Sub
End If
' Check for existing labels and save them
If DataSeries.HasDataLabels Then
' Dimension the array
ReDim LabelsForUndo(1 To cPoints)
' Fill array
For i = 1 To cPoints
LabelsForUndo(i).HasDataLabel =
DataSeries.Points(i).HasDataLabel
If LabelsForUndo(i).HasDataLabel Then
' Save the label text
LabelsForUndo(i).Label =
DataSeries.Points(i).DataLabel.Text
' Save the formatting
With DataSeries.Points(i).DataLabel.Font
LabelsForUndo(i).FontName = .Name
LabelsForUndo(i).FontSize = .Size
LabelsForUndo(i).Color = .Color
LabelsForUndo(i).Bold = .Bold
LabelsForUndo(i).Italic = .Italic
End With
End If
Next
cmdUndo.Enabled = True
End If
' Now do data labels based on options
If optLink Then
For i = 1 To cPoints
DataSeries.Points(i).HasDataLabel = True
DataSeries.Points(i).DataLabel.Text = "=" &
rngLabels.Parent.Name _
& "!" & rngLabels.Cells(i).Address(ReferenceStyle:=xlR1C1)
If chkOption Then
' Set number format link
DataSeries.Points(i).DataLabel.NumberFormatLinked = True
End If
Next
Else
For i = 1 To cPoints
Search JabSto ::




Custom Search