• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Automate selected series last data point labelling in combo chart with lines and stacked area

I would like to add last point data labels to some selected series. I have a combo figure with "line" and "stacked area". I would like to only show last point data label for the "line" series, but not "stacked area", how can I do this in VBA?

I have been able to build a button-click macro to generate data label, but it will generate data label for all series (I don't want it for "stacked area"). See my code below. Can someone enlighten me how to do it please? The reason I'm looping through charts is because I have two charts. The time series are plotted using name ranges for potential update. See attached excel

Any helpful comments greatly appreciated!
Thanks.

Code:
Sub LastDataLables()

    Dim oChart As ChartObject
    Dim MySeries As Series

    For Each oChart In ActiveSheet.ChartObjects
      For Each MySeries In oChart.Chart.SeriesCollection

          'Clear ExistingData Labels
            MySeries.ApplyDataLabels (xlDataLabelsShowNone)

            MySeries.Points(MySeries.Points.Count - 1).ApplyDataLabels

        With MySeries.DataLabels
          .Font.Size = 12
          '.Position = xlLabelPositionRight 
          .NumberFormat = "0.00%"
        End With

      Next MySeries
      Next oChart
End Sub
 

Attachments

Back
Top