title: Runtime Error: 1004 Reference is Not Valid resulting from Goal Seek
body: <p>First of all, here is the Excel chart in question, before running the code:</p>
  
  <p><img src="https://i.stack.imgur.com/Hr34q.png" alt="enter image description here"></p>
  
  <p>and after running the code:</p>
  
  <p><img src="https://i.stack.imgur.com/SfVE7.png" alt="enter image description here"></p>
  
  <p>Here is the code in question:</p>
  
  <pre><code>Option Explicit
  
  Dim Counter As Long
  Dim DeSimpleFinal As Double
  
  Sub SimpleDeCalculationNEW()
  
  Counter = 13
  Range("C1") = "CFL Calculated"
  Range("D1") = "Residual Squared"
  Range("E1") = "De value"
  Range("F1") = 0.2
  
  'Inserting Equations
  Range("C2") = "=((2 * $H$2)/ $H$1) * SQR(($F$1 * A2) / PI())"
  Range("C2").Select
  Selection.AutoFill Destination:=Range("C2:C" &amp; Counter + 1), Type:=xlFillDefault
  
  Range("D2") = "=((ABS(B2-C2))^2)"
  Range("D2").Select
  Selection.AutoFill Destination:=Range("D2:D" &amp; Counter + 1), Type:=xlFillDefault
  
  'Summing up the residuals squared
  Range("D" &amp; Counter + 2) = "=Sum(D2, D" &amp; Counter + 1 &amp; ")"
  
  Columns("A:Z").EntireColumn.EntireColumn.AutoFit
  
  'Goal Seek
  Range("D" &amp; Counter + 2).GoalSeek Goal:=0, ChangingCell:=Range("F1")
  
  DeSimpleFinal = Range("F1")
  'Range("XFD1048523") = DeSimpleFinal
  
  MsgBox ("The Final Value for DeSimple is: " &amp; DeSimpleFinal)
  
  End Sub
  </code></pre>
  
  <p>I keep getting this error, Runtime Error: 1004 Reference is Not Valid, and all of those name errors on the worksheet. Does anybody know how I can fix this? I'm trying to get the sum of the residuals squared as close to zero as possible, in order to get the best possible fit for my data. I do this by using Goal Seek, which is varying the value of De,  given in F1, in order to minimize the sum of the residuals squared, given in D15.</p>
  
  <p>I've gotten this method to work before without issue, and I'm not really sure why it's failing here. Any advice would be amazing!</p>