title: Adding constraints with VBA to the solver tool
body: <p>I am trying to add some new constraints to my excel VBA solver solution and am getting some odd behavior when I run the code. I want to do the following for a minimization problem and am having some trouble:</p>
  
  <p>The two levers that are being adjusted must be &lt;= 35%, however when I add the constraint:</p>
  
  <pre><code>SolverAdd CellRef:="$C$39", Relation:=2, FormulaText:=".35"
  SolverAdd CellRef:="$C$40", Relation:=2, FormulaText:=".35"
  </code></pre>
  
  <p>They automatically set themselves at 35% when the idea is for these to be as low as possible. Without this constraint the cells do set themselves below 35% for the problems I'm validating against, so I know the optimum solution is below 35%.</p>
  
  <p>Also I was wondering if there is a way to make sure that a) the cells are optimized in increments of 5%, and that the ending value does not include decimals. i.e. 10.00% instead of 10.23%</p>
  
  <p>Sorry for the long winded question, I appreciate any help I get.</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>    Private Sub CommandButton2_Click()
  
  Dim i As Integer
  
  
  i = 2
  
  For i = 2 To 5
  
     Range("$C$14").Value = Application.Workbooks("test_model_2.xls").Worksheets("All Models").Cells(i, 2).Value
      SolverReset
      SolverAdd CellRef:="$F$70", Relation:=3, FormulaText:="5000"
      SolverAdd CellRef:="$C$39", Relation:=2, FormulaText:=".35"
      SolverAdd CellRef:="$C$40", Relation:=2, FormulaText:=".35"
      SolverOk SetCell:="$F$70", MaxMinVal:=2, ValueOf:="0", ByChange:="$C$39:$C$40"
      SolverSolve True
     MsgBox "i is:" &amp; i
  
  Next i
  
  End Sub
  </code></pre>