title: Replace "Value From Cells" in chart data labels using VBA
body: <p>I have copied  several charts from a workbook to another and I managed to change the data series with vba.</p>
  
  <p>Some of the data labels of these charts, get data "<strong>From Cells</strong>" but this range is still referencing the the first workbook and I need to change it to reference the new sheet in the new workbook.</p>
  
  <p>I am being able to get the formula that references the "From Cells".</p>
  
  <p>This is the code that I have</p>
  
  <pre><code>Sub xtDataLabels_FromCells()
      Dim oChart As ChartObject
      Dim OldString As String, NewString As String
      Dim mySrs As Variant
  
      OldString = "'[Daily Report]SP'!$P$11:$P$20"
      NewString = "SP!$P$11:$P$20"
  
      For Each oChart In ActiveSheet.ChartObjects
          For Each mySrs In oChart.Chart.SeriesCollection
              ' From a recorded macro
              'ActiveChart.SeriesCollection(7).DataLabels.Format.TextFrame2.TextRange. _
                  InsertChartField msoChartFieldRange, "=SP!$P$11:$P$20", 0
          Next
      Next
  End Sub
  </code></pre>
  
  <p><strong>"Value From Cells"</strong></p>
  
  <p><a href="https://i.stack.imgur.com/513Co.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/513Co.png" alt="enter image description here"></a></p>
  
  <p>Regards,
  Elio Fernandes</p>