Option Explicit
Sub grphLabel()
'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String
Dim sLbl As String, sStg As String
' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False
'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula
'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop
'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
With ActiveChart.SeriesCollection(1).Points(Counter)
sLbl = Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
'## the -1 in the Offset above is the postion of the column _
## holding the year compared to the rightmost column of _
## graph values
.HasDataLabel = True
.DataLabel.Text = sLbl
If Range(xVals).Cells(Counter, 1).Value < Range(xVals).Cells(Counter, 1).Offset(0, 1).Value Then
.MarkerBackgroundColor = RGB(255, 50, 50)
.MarkerForegroundColor = RGB(255, 50, 50)
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 7
With .DataLabel.Format
.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 50, 50)
End With
Else
.MarkerBackgroundColor = RGB(0, 0, 255)
.MarkerForegroundColor = RGB(0, 0, 255)
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 7
With .DataLabel.Format
.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(20, 20, 255)
End With
End If
End With
Next Counter
End Sub