0

I am trying to delete all data labels in an Excel chart for each of the series but somehow my code doesn't delete any of the data labels on the chart. Please let me know if there is something lacking in my code below. I am currently using Microsoft Office 365 and the file is an xlsb .

Thanks in advance and really appreciate your help.

Sub DeleteDataLabels()
Sheets("Sheet1").Select
Call UnprotectSheet
ActiveSheet.ChartObjects("Chart 2").Activate


SeriesCount = ActiveChart.SeriesCollection.Count
MsgBox SeriesCount

' To delete the code
For i = 1 To SeriesCount
ActiveChart.SeriesCollection(i).Select
ActiveChart.ChartArea.Select
If ActiveChart.SeriesCollection(i).HasDataLabels Then
            ActiveChart.SeriesCollection(i).DataLabels.Select
            Selection.Delete
End If
Next i
End Sub
AnalysisNerd
  • 111
  • 2
  • 16

1 Answers1

1

Thanks to @Rory's comment. Replace the if statement with the line of code below the comment.

 Sub DeleteDataLabels()

 Sheets("Sheet1").Select
 Call UnprotectSheet
 ActiveSheet.ChartObjects("Chart 2").Activate


 SeriesCount = ActiveChart.SeriesCollection.Count
 MsgBox SeriesCount

 'Replace the if statement with this line of code
 ActiveChart.ApplyDataLabels xlDataLabelsShowNone
 End Sub
AnalysisNerd
  • 111
  • 2
  • 16