title: VBA Macro optimization using Solver in Excel not returning optimal variables
body: <p>I am trying to optimize three parameters in Excel in order to minimize the error between a experimental value and a theoretical value. I use Solver for each parameter, one at a time, in a for loop. However, I want to iterate this solver for loop (loop inside a loop) until the error in the experimental value and the theoretical value is less than some target value.</p>
  
  <p>My experimental value is <code>$K25</code>.<br>
  My theoretical value (calculated based on my model equations) is <code>$J$25</code>.<br>
  My parameters that need to be optimized are <code>$C$4</code>, <code>$C$5</code>, <code>$C$6</code></p>
  
  <p>When I run the following VBA code my parameters in  <code>$C$4</code>, <code>$C$5</code>, <code>$C$6</code> do not change from their initial values. However, the macro compiles fine with no errors. Can anyone help me out here?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>Sub Macro3()
      Application.ScreenUpdating = False
      SolverReset
      Dim j As Integer
      For j = 1 To 100 Step 1
          If "$J$25" &gt; "$K$25" Then
              Dim i As Integer, s As String
              For i = 4 To 6 Step 1
              s = Format(i, "0")
                  SolverOk SetCell:="$J$25", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$" &amp; s, Engine:= _
                  1, EngineDesc:="GRG Nonlinear"
                  SolverOptions MaxTime:=0, Iterations:=1000000, Precision:=0.000001, Convergence _
                  :=0.00001, StepThru:=False, Scaling:=True, AssumeNonNeg:=True, Derivatives:=1
                  SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
                  :=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
                  IntTolerance:=1, SolveWithout:=False, MaxTimeNoImp:=30
                  SolverOk SetCell:="$J$25", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$" &amp; s, Engine:= _
                  1, EngineDesc:="GRG Nonlinear"
                  SolverSolve (True)
                  SolverReset
              Next i
          End If
      Next j
      Application.ScreenUpdating = True
  End Sub
  </code></pre>