title: Excel VBA Charts -> range select using "Cells" in within Charts
body: <p>I'm trying to modify an existing VBA code (Excel) which makes Chart graphs, and make it more flexible.</p>
  
  <p>I know that the following pieces of code do basically the same thing:</p>
  
  <pre><code>Range(Cells(12, 2), Cells(15, 2)).Select    
  </code></pre>
  
  <p>is more or less identical to: </p>
  
  <pre><code>Range("B12:B15").Select    
  </code></pre>
  
  <p>My goal was to have a Graph, which is representing the flexible count of rows.</p>
  
  <p>So I have changed the existing code:</p>
  
  <pre><code>ActiveChart.SetSourceData Source:=Sheets("Log-Data").Range("B12:B200"), PlotBy:=xlColumns    
  </code></pre>
  
  <p>to </p>
  
  <pre><code>Dim LastRow As Integer
  LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row    
  ActiveChart.SetSourceData Source:=Sheets("Log-Data").Range(Cells(12, 2), Cells(LastRow, 2)), PlotBy:=xlColumns    
  </code></pre>
  
  <p>Now, whenever I execute the code, I receive:</p>
  
  <blockquote>
    <p>Run-time error '1004': Application-defined or object-defined error</p>
  </blockquote>
  
  <p>The <code>LastRow</code> variable is not the problem: I have the same result if I replace it with 200. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>Cheers</p>
  
  <p>Peter </p>