PDA

View Full Version : VBA 2011 Overlapping Datalabels



cyrilbrd
10-01-2012, 02:10 AM
following this thread (http://www.vbaexpress.com/forum/showthread.php?t=43828).

I use this code to toggle the data labels on a line chart:
Sub ToggleDataLabelsSecondAxis1()

Dim lngSeries As Long
Dim xx As DataLabels
With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(5)

.HasDataLabels = Not .HasDataLabels
If .HasDataLabels Then
With .DataLabels
.ShowCategoryName = False
.ShowValue = True
.ShowSeriesName = False
.Orientation = 90
.Position = 0
End With
End If
End With


End Sub

and for the other line:
Sub ToggleDataLabelsSecondAxis2()

Dim lngSeries As Long
Dim xx As DataLabels
With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(6)

.HasDataLabels = Not .HasDataLabels
If .HasDataLabels Then
With .DataLabels
.ShowCategoryName = False
.ShowValue = True
.ShowSeriesName = False
.Orientation = 90
.Position = 1
End With
End If
End With


End Sub

What code would you suggest to avoid having data labels overlapping for similar data.
Eg
67.46 78.29 67.63 72.12 86.12 75.84 Those are close enough to make some labels unreadable.
Adjusting manually (although possible) would be counter productive as pdf (another thread / feature) are create on the go.

Thnks.