Class DataLabel (Excel VBA)

The class DataLabel represents the data label on a chart point or trendline.

The main procedures of class DataLabel are Delete, Select, DataLabels.Delete and DataLabels.Select

Set

To use a DataLabel class variable it first needs to be instantiated, for example

Dim lngIndex As Long: lngIndex = 
Dim srs As Series: Set srs = 
Dim dtlDataLabel As DataLabel
Set dtlDataLabel = srs.DataLabels(Index:=lngIndex)

The following procedures can be used to set variables of type DataLabel: DataLabels.Item, Point.DataLabel, Trendline.DataLabel and Series.DataLabels

For Each

Here is an example of processing the DataLabel items in a collection.

Dim srs As Series: Set srs = 
Dim dtlDataLabel As DataLabel
For Each dtlDataLabel In srs.DataLabels()
	
Next dtlDataLabel

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Formula with its procedures Formula, FormulaLocal, FormulaR1C1 and FormulaR1C1Local
Number with its procedures NumberFormatLinked, NumberFormatLocal, DataLabels.NumberFormatLinked and DataLabels.NumberFormatLocal
Sort/Order with its procedures ReadingOrder and DataLabels.ReadingOrder
Display/Show with its procedures ShowBubbleSize, ShowCategoryName, ShowLegendKey, ShowPercentage, ShowRange, ShowSeriesName, DataLabels.ShowBubbleSize, DataLabels.ShowCategoryName, DataLabels.ShowLegendKey, DataLabels.ShowPercentage, DataLabels.ShowRange and DataLabels.ShowSeriesName

Methods

These are the main methods of the DataLabel class

Delete - Deletes the object.

Select - Selects the object.

DataLabels.Delete - Deletes the object.

DataLabels.Select - Selects the object.

Properties

AutoText true if the object automatically generates appropriate text based on context.

Charts("Chart1").SeriesCollection(1).DataLabels.AutoText = True

Caption returns or sets a String value that represents the data label text.

Characters returns a Characters object that represents a range of characters within the object text. You can use the Characters object to format characters within a text string.

Format returns the ChartFormat object.

Height returns the height of the object in points.

HorizontalAlignment returns or sets a value that represents the horizontal alignment for the specified object.

Left returns or sets a Double value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).

Name returns a String value that represents the name of the object.

NumberFormat returns or sets a String value that represents the format code for the object.

Orientation returns or sets a value that represents the text orientation.

Parent returns the parent object for the specified object. Read-only.

Position returns or sets an XlDataLabelPosition value that represents the position of the data label.

Separator sets or returns a Variant representing the separator used for the data labels on a chart.

Sub ChangeSeparator() 
 
 ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1) _ 
 .DataLabels.Separator = ";" 
 
End Sub

Shadow returns or sets a Boolean value that determines if the object has a shadow.

ShowValue returns or sets a Boolean corresponding to a specified chart's data label values display behavior. True displays the values. False to hide.

Sub UseValue() 
 
 ActiveSheet.ChartObjects(1).Activate 
 ActiveChart.SeriesCollection(1) _ 
 .DataLabels.ShowValue = True 
 
End Sub

Text returns or sets the text for the specified object.

Top returns or sets a Double value that represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

VerticalAlignment returns or sets a value that represents the vertical alignment of the specified object.

Width returns the width of the object in points.

DataLabels.AutoText true if the object automatically generates appropriate text based on context.

Charts("Chart1").SeriesCollection(1).DataLabels.AutoText = True

DataLabels.Count returns a Long value that represents the number of objects in the collection.

DataLabels.Format returns the ChartFormat object.

DataLabels.HorizontalAlignment returns or sets a value that represents the horizontal alignment for the specified object.

DataLabels.Name returns a String value that represents the name of the object.

DataLabels.NumberFormat returns or sets a String value that represents the format code for the object.

DataLabels.Orientation returns or sets a value that represents the text orientation.

DataLabels.Parent returns the parent object for the specified object. Read-only.

DataLabels.Position returns or sets an XlDataLabelPosition value that represents the position of the data label.

DataLabels.Separator sets or returns a Variant representing the separator used for the data labels on a chart.

Sub ChangeSeparator() 
 
 ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1) _ 
 .DataLabels.Separator = ";" 
 
End Sub

DataLabels.Shadow returns or sets a Boolean value that determines if the object has a shadow.

DataLabels.ShowValue returns or sets a Boolean corresponding to a specified chart's data label values display behavior. True displays the values. False to hide.

Sub UseValue() 
 
 ActiveSheet.ChartObjects(1).Activate 
 ActiveChart.SeriesCollection(1) _ 
 .DataLabels.ShowValue = True 
 
End Sub

DataLabels.VerticalAlignment returns or sets a value that represents the vertical alignment of the specified object.