title: Can't write to dynamic range
body: <p>I want to make an automatically updating range on an excel sheet with multiple tables.</p>
  
  <p>I have</p>
  
  <pre><code>Dim datarange as Range
  Dim dataend as Integer
  dataend = Worksheets("Sheet2").Range("B2").CurrentRegion.Rows.Count
  Set datarange = Worksheets("Sheet2").Range(Cells(2, 2), Cells(8, dataend))
  </code></pre>
  
  <p>This is to update the range for a chart on another sheet.</p>
  
  <p>When I print <code>Worksheets("Sheet2").Range("B2").CurrentRegion.Rows.Count</code> in the immediate window it returns the number 7, so I know that it is counting the rows.  But when I try to run the code I get an error saying "Application defined or object defined error."  I don't know why the Cells property won't take the value of the <code>dataend</code> variable.</p>