Created
December 24, 2016 04:27
-
-
Save airstrike/48c13d3b28768ebd5cb48a60fd211228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'from http://peltiertech.com/Excel/Charts/LabelLastPoint.html | |
Sub LastPointLabel() | |
Dim mySrs As Series | |
Dim iPts As Long | |
Dim bLabeled As Boolean | |
If ActiveChart Is Nothing Then | |
MsgBox "Select a chart and try again.", vbExclamation, "No Chart Selected" | |
Else | |
For Each mySrs In ActiveChart.SeriesCollection | |
bLabeled = False | |
With mySrs | |
For iPts = .Points.Count To 1 Step -1 | |
If bLabeled Then | |
' handle error if point isn't plotted | |
On Error Resume Next | |
' remove existing label if it's not the last point | |
mySrs.Points(iPts).HasDataLabel = False | |
On Error GoTo 0 | |
Else | |
' handle error if point isn't plotted | |
On Error Resume Next | |
' add label | |
mySrs.Points(iPts).ApplyDataLabels _ | |
ShowSeriesName:=True, _ | |
ShowCategoryName:=False, ShowValue:=False, _ | |
AutoText:=True, LegendKey:=False | |
bLabeled = (Err.Number = 0) | |
On Error GoTo 0 | |
End If | |
Next | |
End With | |
Next | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment