Reputation: 907
How do I check if a chart has labels? At the moment the graph is erroring because I am trying to delete labels that do not exist.
Sub deltelabels()
Dim x As Integer
ActiveSheet.ChartObjects("Chart 4").Activate
For x = 1 To 4
ActiveChart.FullSeriesCollection(x).DataLabels.Delete
Next x
End Sub
Upvotes: 0
Views: 1424
Reputation: 907
Sub CheckChartLabels()
Dim cht As Chart
Dim ser As Series
Dim HasLabels As Long
Set cht = Sheets("Page 3").ChartObjects("Chart 4").Chart
For Each ser In cht.SeriesCollection
If ser.HasDataLabels Then ser.DataLabels.Delete
Next
End Sub
Upvotes: 1