VBA looping through all series within all charts

前端 未结 2 1831
陌清茗
陌清茗 2021-01-19 01:59

I\'m having an issue with the looping through of several charts in my VBA code. I\'m 99.7% sure that this is a really easy and quick fix but my brain isn\'t working today.

相关标签:
2条回答
  • 2021-01-19 02:35

    Not work for empty values.

    This code find last not empty value and then adds label.

    For Each mySrs In myChartObject.Chart.SeriesCollection
          Set myPts = mySrs.Points
          Dim i As Integer
          i = myPts.Count
          Do Until i < 2 Or mySrs.Values(i) <> ""
            i = i - 1
          Loop
          myPts(i).ApplyDataLabels Type:=xlShowValue
    Next
    
    0 讨论(0)
  • 2021-01-19 02:48

    Try following code:

    Sub AddLastValue()
        Dim myChartObject As ChartObject
        Dim mySrs As Series
        Dim myPts As Points
    
        With ActiveSheet
            For Each myChartObject In .ChartObjects
                For Each mySrs In myChartObject.Chart.SeriesCollection
                    Set myPts = mySrs.Points
                    myPts(myPts.Count).ApplyDataLabels Type:=xlShowValue
                Next
            Next
        End With
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题