PDA

View Full Version : Delete all Datalabels on Chart Except Current Dates



anne.gomes
06-18-2014, 06:31 PM
Hi,

I am trying to delete all datalabels in a chart except for the current dates'.

This is my code - which isnt working...



Sub Auto_Open()

Dim sery As Series
Dim Today As Date
Today = Date
Sheets("BU Aged Analysis WIP").Select

For Each sery In ActiveChart.SeriesCollection
If sery.HasDataLabels = True Then
If sery.DataLabels <> Today Then
sery.DataLabels.Select
Selection.Delete

End If

End If

Next sery

End Sub



Any help?

Bob Phillips
06-19-2014, 02:03 AM
Sub Auto_Open()
Dim sery As Series
Dim label As DataLabel
Dim Today As Date

Today = Date
Sheets("BU Aged Analysis WIP").Select

For Each sery In ActiveChart.SeriesCollection

If sery.HasDataLabels = True Then

For Each label In sery.DataLabels

If label.Caption <> Today Then

label.Delete
End If
Next label
End If
Next sery
End Sub

anne.gomes
06-19-2014, 07:28 PM
hi xld,

it deletes all the data labels....

Ive tried so many ways, I just can't keep the current date value on the graph :/

EirikDaude
06-20-2014, 01:39 AM
You could try to change

If label.Caption <> Today Then
To

If label.Caption <> CStr(Today) Then
If that doesn't work, you could try to put

Debug.Print(label.Caption & " - " & CStr(Today))
next to the line which deletes the labels to see how the two string values differ when it prints today's date.

anne.gomes
06-23-2014, 02:29 PM
Thank you EirikDaude :)