Data labels every second point

K

Klemen25

Hello

I found and successfully used the below stated macro for adding data
labels on the last data point.
Could someone of you experts help me with creating a macro, that would
add data labels on every second point (when there are a lot of data
the labels are too crowded, and to erase manually every second label
is quite time consuming)

Thank you all!


Sub LastPoinLabel()
Dim mySrs As Series
Dim nPts As Long
On Error GoTo Error
For Each mySrs In ActiveChart.SeriesCollection
With mySrs
nPts = .Points.Count
mySrs.Points(nPts).ApplyDataLabels _
Type:=xlDataLabelsShowValue, _
AutoText:=True, LegendKey:=False


End With
Next
Error: Exit Sub
End Sub
 
K

Klemen25

Oh yes- I have excel 2003; and we are talking about charts- line chart
in perticular. :)
 
D

Dave Peterson

Untested, uncompiled:

Sub LastPoinLabel()
Dim mySrs As Series
Dim nPts As Long
dim nCtr as long
On Error GoTo ErrorExit
For Each mySrs In ActiveChart.SeriesCollection
With mySrs
nPts = .Points.Count
for nctr = 2 to npts step 2
mySrs.Points(nctr).ApplyDataLabels _
Type:=xlDataLabelsShowValue, _
AutoText:=True, LegendKey:=False
next nctr
End With
Next mySrs
ErrorExit: Exit Sub
End Sub

or maybe
for nctr = 1 to npts step 2
Depending on which one you want to start with.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top