PDA

View Full Version : Looping through and Deleting data in Pivot chart



anne.gomes
06-12-2014, 05:17 PM
What is a better way of writing this?




Sub Macro1()
Dim chlabels As Integer
chlabels = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)
For Each DataLabel In chlabels
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(chlabels).DataLabels.Select
Selection.Delete

Next DataLabel

End Sub

westconn1
06-14-2014, 03:41 AM
Dim chlabels As Integer
chlabels = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)
does this work at all, i would expect an error, as array returns a variant


For Each DataLabel In chlabels
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(chlabels).DataLabels.Select you are passing the array as an index for seriescollection, instead of the member of the array, avoid using reserved words (i believe Datalabel woud be one) as variables

Bob Phillips
06-14-2014, 03:56 AM
Sub RemoveDatalabels()
Dim chtseries As Series

With ActiveChart

For Each chtseries In .SeriesCollection

chtseries.DataLabels.Delete
Next chtseries
End With
End Sub