title: Select data range for a chart from different sheet using VBA (EXCEL)
body: <p>How can I select data range for a chart from different sheet using VBA? Suppose that data sheet name is <code>data_sheet</code>, chart sheet name is <code>chart_sheet</code>, and my data range is <code>A1:A20</code>. How can I do this in excel? I checked <a href="https://stackoverflow.com/questions/14388270/setting-a-chart-source-data-based-on-a-variable-cell-range-in-vba">THIS</a> but didn't work for different sheets. Otherwise, I checked <a href="https://stackoverflow.com/questions/23630091/update-chart-with-setsourcedata-in-a-chart-sheet">THIS</a> but returned this error: <code>Subscript out of range</code>:</p>
  
  <pre><code> With Worksheets("chart_sheet")
         ActiveChart.SetSourceData Source:=Worksheets("data_sheet").Range("A1:A20")
   End With
  </code></pre>