title: Type Mismatch Error in VBA code during solver optimization
body: <p>I am getting a type mismatch error on my excel and vba based optimization problem. I am using Frontline Solver trial edition which I used before last year. When I run the code (which was a slight modification of my earlier trial) I get this error.I know that it may occur when there is an error in excel cells, format or content.
  In my code, initially, I set the range which will be changed to find the solution to zero. The error comes up in the line below</p>
  
  <pre><code>SolverOK SetCell:="$H$31", MaxMinVal:=1, ByChange:=rngAll
  </code></pre>
  
  <p>At that moment frontline sets these ranges to the range definition, it is seen like $J$2:$J$27,$R$2:$R$27,$Z$2:$Z$27. This may not be important though. </p>
  
  <p>This is the whole function</p>
  
  <pre><code>Sub LPOptimization1()
  
   Dim LPOptimization1Sheet
   Set LPOptimization1Sheet = Worksheets("LP Optimization 1")
  
   Worksheets("LP Optimization 1").Activate
   SolverReset
   SolverOptions Precision:=0.001
  
   Dim rng1, rng2, rng3, rngAllTemp, rngAll  As Range
  
  
   Set rng1 = Range("J2:J27")
   Set rng2 = Range("R2:R27")
   Set rng3 = Range("Z2:Z27")
  
   rng1.Value = 0
   rng2.Value = 0
   rng3.Value = 0
  
  'Relation 1 kucuk esit, 2 esit, 3 buyuk esit
  
  
   Dim i As Integer
  
  For i = 2 To 28 '22--&gt; 24 26--&gt;28
  
  'Precaution X
      If LPOptimization1Sheet.Cells(i, 7).Value &lt;&gt; "Non" Then
  
          If LPOptimization1Sheet.Cells(i, 9).Value = "0" Then
              SolverAdd CellRef:="$J$" &amp; i &amp; ":$J$" &amp; i, Relation:=2, FormulaText:=1
          End If
  
          If LPOptimization1Sheet.Cells(i, 12).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 12).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 12).Value) = False Then
              SolverAdd CellRef:="$J$" &amp; i &amp; ":$J$" &amp; i, Relation:=3, FormulaText:="$L$" &amp; i &amp; ":$L$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 13).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 13).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 13).Value) = False Then
              SolverAdd CellRef:="$J$" &amp; i &amp; ":$J$" &amp; i, Relation:=1, FormulaText:="$M$" &amp; i &amp; ":$M$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 14).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 14).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 14).Value) = False Then
              SolverAdd CellRef:="$K$" &amp; i &amp; ":$K$" &amp; i, Relation:=1, FormulaText:="$N$" &amp; i &amp; ":$N" &amp; i
          End If
      Else
          SolverAdd CellRef:="$J$" &amp; i &amp; ":$J$" &amp; i, Relation:=2, FormulaText:=0
      End If
  
  
  
  'Precaution Y
      If LPOptimization1Sheet.Cells(i, 15).Value &lt;&gt; "Non" Then
          If LPOptimization1Sheet.Cells(i, 17).Value = "0" Then
              SolverAdd CellRef:="$R$" &amp; i &amp; ":$R$" &amp; i, Relation:=2, FormulaText:=1
          End If
  
          If LPOptimization1Sheet.Cells(i, 20).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 20).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 20).Value) = False Then
              SolverAdd CellRef:="$R$" &amp; i &amp; ":$R$" &amp; i, Relation:=3, FormulaText:="$T$" &amp; i &amp; ":$T$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 21).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 21).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 21).Value) = False Then
              SolverAdd CellRef:="$R$" &amp; i &amp; ":$R$" &amp; i, Relation:=1, FormulaText:="$U$" &amp; i &amp; ":$U$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 22).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 22).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 22).Value) = False Then
              SolverAdd CellRef:="$S$" &amp; i &amp; ":$S$" &amp; i, Relation:=1, FormulaText:="$V$" &amp; i &amp; ":$V" &amp; i
          End If
      Else
          SolverAdd CellRef:="$R$" &amp; i &amp; ":$R$" &amp; i, Relation:=2, FormulaText:=0
      End If
  
  
  'Precaution Z
      If LPOptimization1Sheet.Cells(i, 23).Value &lt;&gt; "Non" Then
          If LPOptimization1Sheet.Cells(i, 25).Value = "0" Then
              SolverAdd CellRef:="$Z$" &amp; i &amp; ":$Z$" &amp; i, Relation:=2, FormulaText:=1
          End If
          If LPOptimization1Sheet.Cells(i, 28).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 28).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 28).Value) = False Then
              SolverAdd CellRef:="$Z$" &amp; i &amp; ":$Z$" &amp; i, Relation:=3, FormulaText:="$AB$" &amp; i &amp; ":$AB$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 29).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 29).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 29).Value) = False Then
              SolverAdd CellRef:="$Z$" &amp; i &amp; ":$Z$" &amp; i, Relation:=1, FormulaText:="$AC$" &amp; i &amp; ":$AC$" &amp; i
          End If
  
          If LPOptimization1Sheet.Cells(i, 30).Value &lt;&gt; "" And IsNull(LPOptimization1Sheet.Cells(i, 30).Value) = False And IsEmpty(LPOptimization1Sheet.Cells(i, 30).Value) = False Then
              SolverAdd CellRef:="$AA$" &amp; i &amp; ":$AA$" &amp; i, Relation:=1, FormulaText:="$AD$" &amp; i &amp; ":$AD" &amp; i
          End If
      Else
          SolverAdd CellRef:="$Z$" &amp; i &amp; ":$Z$" &amp; i, Relation:=2, FormulaText:=0
      End If
  Next i
  
  'Total Cost
   SolverAdd CellRef:="$D$31:$D$31", Relation:=1, FormulaText:="$B$31:$B$31"
  
  
   SolverAdd CellRef:="$J$2:$J$27", Relation:=4, FormulaText:="integer"
   SolverAdd CellRef:="$R$2:$R$27", Relation:=4, FormulaText:="integer"
   SolverAdd CellRef:="$Z$2:$Z$27", Relation:=4, FormulaText:="integer"
  
  
  'Set rng1 = Range("J2:J27")
  'Set rng2 = Range("R2:R27")
  'Set rng3 = Range("Z2:Z27")
  
  
  'Set rngAllTemp = Application.Union(rng1, rng2)
  'Set rngAll = Application.Union(rng1, rng2, rng3)
  
  Set rngAll = Union([J2:J27], [R2:R27], [Z2:Z27])
  
  
  '1 Maximize 2 Minimize 3 Match a Specific Value
  SolverOK SetCell:="$H$31", MaxMinVal:=1, ByChange:=rngAll
  
  
   SolverOptions MaxTime:=100000, Iterations:=10000, Precision:=0.0000001, AssumeLinear:=False, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _
   IntTolerance:=0, Scaling:=False, Convergence:=0.001, AssumeNonNeg:=True
   SolverSolve UserFinish:=False
  
   SolverFinish KeepFinal:=1
  
  End Sub
  </code></pre>
  
  <p>Since I am using the trial version I have little time to fix this issue. I will be very happy to hear from people who can help... Thanks in advance... </p>
  
  <p>Ferda</p>