title: VBA - Multiple series to a chart
body: <p>I'm trying to make add two series to a single XYscatter chart via loop. Currently, my code creates two charts. The X values are constant but the Y values change so I added them to an array to preserve them. </p>
  
  <pre><code>Sub test()
      Dim sh As Worksheet
      Set sh = ThisWorkbook.Sheets("Sheet1")
      Dim thearray(9) As Double
      Dim chrt As Chart
      Dim n As Integer, i As Integer, q As Integer
      For q = 1 To 2
          For i = 0 To 9
              thearray(i) = WorksheetFunction.RandBetween(1, 20)
          Next
          Set chrt = sh.Shapes.AddChart.Chart
          With chrt
              .ChartType = xlXYScatterLines
              .SeriesCollection.NewSeries
              .SeriesCollection(1).Name = "TEST"
              .SeriesCollection(1).XValues = Range("B2:K2")
              .SeriesCollection(1).Values = thearray
              .SeriesCollection(1).MarkerSize = 4
              For n = .SeriesCollection.Count To 2 Step -1
                  .SeriesCollection(n).Delete
              Next n
          End With
      Next
  End Sub
  </code></pre>
  
  <p>I appreciate any help offered.</p>
  
  <p>Edit: I tried changing</p>
  
  <pre><code>.SeriesCollection(1)
  </code></pre>
  
  <p>To </p>
  
  <pre><code>.SeriesCollection(q)
  </code></pre>
  
  <p>But it doesn't work.</p>
  
  <p>EDIT2: I  figured it out. I took </p>
  
  <pre><code> Set chrt = sh.Shapes.AddChart.Chart
  </code></pre>
  
  <p>Out of  the loop and replaced 1 with q in .SeriesCollection</p>