title: Repeated calls of Chart.SetSourceData give error 1004
body: <p>I have a problem with an application that was created in Excel 2003 in my company. The application retrieves data from a source and updates a Chart using the <code>SetSourceData</code> in a VBA routine passing a Range containing the cells where the relevant data is written.</p>
  
  <p>The application runs just fine in Office 2003, but when the application is executed in Office 2010 it gives this error: </p>
  
  <blockquote>
    <p>Run-time error '1004': Method 'SetSourceData' of object'_Chart' failed.</p>
  </blockquote>
  
  <p>I have created a <code>For</code> loop in a simple Excel file in Office 2010 and depending on the number of columns passed in the Range to the Chart the error will come up sooner or later. The more columns passed in the Range the sooner it will come up. I guess this has to be related with the number of series in the Chart(more columns more series).</p>
  
  <p>Is this some sort of mechanism/buffer in the Chart Object or Series implemented in Office 2010 that did not exist in Office 2003? The same <code>For</code> loop never shows a problem when it is run in Office 2003 and I am not sure how to solve this problem.</p>
  
  <p>So far I have only been able to delete all the Series controlling the Error with a Goto instruction to delete all the series in the SeriesCollection using a <code>For Each</code> loop to select all the objects in the SeriesCollection of the Chart. If I do this and resume the execution of the application when I pass the Range again all the data is painted in the Chart Object properly.</p>
  
  <p><strong>Example to reproduce the error.</strong> The following code is to be put in a VBA module in a new Excel 2010 workbook. Run the Sub <code>setDataChart</code> and the application will run until the error message is displayed. </p>
  
  <pre><code>    Sub setDataChart()
      Call createAColValues
      ActiveSheet.Shapes.AddChart.Select
      ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
      ActiveChart.SetSourceData Source:=Range("A1:FA6"), PlotBy:=xlColumns
      ActiveSheet.ChartObjects(1).Activate
      With ActiveChart.Parent
           .Height = 325
           .Width = 900
           .Top = 120
           .Left = 10
      End With
      Call updateValues
      Call sendData
  End Sub
  
      Sub sendData()
      Dim cht As ChartObject
      Set cht = ActiveSheet.ChartObjects(1)
  
      'On Error GoTo delSeries:
      For i = 0 To 1000
          cht.Chart.SetSourceData Source:=ActiveSheet.Range("A1:FA6"), PlotBy:=xlColumns
      Next i
  End Sub
  
  Sub createAColValues()
      Range("A1").Select
      ActiveCell.FormulaR1C1 = "1"
      Range("A2").Select
      ActiveCell.FormulaR1C1 = "2"
      Range("A1:A2").Select
      Selection.AutoFill Destination:=Range("A1:A6"), Type:=xlFillDefault
      Range("A1:A6").Select
  End Sub
  
  Sub updateValues()
      Range("B1").Select
      ActiveCell.FormulaR1C1 = "=RANDBETWEEN(0,10)"
      Range("B1").Select
      Selection.AutoFill Destination:=Range("B1:B6"), Type:=xlFillDefault
      Range("B1:B6").Select
      Selection.AutoFill Destination:=Range("B1:FA6"), Type:=xlFillDefault
      Range("B1:FA6").Select
  End Sub
  </code></pre>