Consulting

Results 1 to 5 of 5

Thread: Delete all Datalabels on Chart Except Current Dates

  1. #1

    Delete all Datalabels on Chart Except Current Dates

    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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 :/

  4. #4
    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.

  5. #5
    Thank you EirikDaude

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •