title: Excel VBA - Get chart data range
body: <p>I want to add data to a bunch of existing charts. Assume that each chart has a different number of data series and that the location of the raw data is somewhere in the same workbook. Here's what I'm starting with:</p>
  <pre><code>For iChart = 1 To iCount
      ActiveSheet.ChartObjects(&quot;Chart &quot; &amp; iChart).Activate
      intSeries = 1
      Do Until ActiveChart.SeriesCollection(intSeries).Name = &quot;&quot;
          Set rXVal = ActiveChart.SeriesCollection(intSeries).XValues '&lt;- Object Required error
          Set rXVal = Range(rXVal, rXVal.End(xlDown))
          Set rYVal = ActiveChart.SeriesCollection(intSeries).Values
          Set rYVal = Range(rYVal, rYVal.End(xlDown))
          ActiveChart.SeriesCollection(intSeries).XValues = rXVal
          ActiveChart.SeriesCollection(intSeries).Values = rYVal
          intSeries = intSeries + 1
      Loop
  Next iChart
  </code></pre>
  <p>I know that <code>ActiveChart...XValues = rXVal</code> works, but I'm getting an &quot;Object Required&quot; error on the <code>Set rXVal = ActiveChart....XValues</code> line. I'm assuming that since a range went in to define the data series, I can get that range back out again and then add to it.</p>
  <p><strong>UPDATE</strong><br />
  To clarify things a little, I have accelerometers in 8 places and FFT software setup to record peak vibration response in 4 separate frequency bands. This yields 32 data points per sample. When exporting, the software spits out an Excel workbook with 4 sheets; one for each frequency band. Each sheet has the accelerometer names going across and sample numbers going down.</p>