title: Excel XY chart coordinates for data labels loop through multiple chart template
body: <p>Can anyone help me adjust the following code to loop through the range of datapoints for two data series? Also help me to loop through multiple charts on different sheets in the same workbook? Also is there a way to asign the incremetal <code>.Left = XVal</code> to a a calculated cell so that this adjusts automatically depending on axis/ number of data points displayed?</p>
  
  <p>This is for an XY chart - I came across the code <a href="https://www.mrexcel.com/forum/excel-questions/337847-vba-accessing-coordinates-data-series-chart.html" rel="nofollow noreferrer">here</a> and it gets the coordinates of a data point and positions the datalabels above the data series. I have two data series on each chart that I need to use this for - SeriesCollection 5 and SeriesCollection 3. I have used an incremental <code>.Left = XVal</code> incremental value so that the data labels position sequentially at the top of the chart. </p>
  
  <pre><code>Public Sub ChangeCoordinates()
      Dim cht As Excel.Chart
      Dim srs As Excel.Series
  
      Dim i As Long
  
      Set cht = Application.ActiveChart
      Set srs = cht.SeriesCollection(5)
  
      For i = 1 To srs.Points.Count
          XVal = ExecuteExcel4Macro("GET.CHART.ITEM(1,1,""S1P" &amp; i &amp; """)")
          YVal = ExecuteExcel4Macro("GET.CHART.ITEM(2,1,""S1P" &amp; i &amp; """)")
  
          With ActiveChart.SeriesCollection(5).Points(1).DataLabel
              .Left = XVal - 550
              .Top = YVal + 50
          End With
  
          With ActiveChart.SeriesCollection(5).Points(2).DataLabel
              .Left = XVal - 500
              .Top = YVal + 50
          End With
      Next i
  End Sub
  </code></pre>