Excel Solver problem

sudhakar682

Board Regular
Joined
May 11, 2003
Messages
163
hi,

I wrote a small code to run solver. In the code I specified to add four constraints, but when I click the button (to run solver) only two constraints appear in the solver? Does anyone know why my other two constraints aren't appearing in the solver? Thanks very much for your time.

Public Sub Calculate_Equity_Duration_Module()

Dim ObjCell As Variant
Dim ChangeCell As Variant
Dim ConstraintOne As Variant
Dim ConstraintTwo As Variant
Dim ConstraintThree As Variant
Dim ConstraintFour As Variant
Dim Target_Return As Variant
Dim Plan_Duration As Variant


Worksheets("Equity_Duration").Activate
Target_Return = Range(Cells(2, 3), Cells(2, 3)).Value
Plan_Duration = Range(Cells(3, 3), Cells(3, 3)).Value

ObjCell = Cells(16, 3).Address()
ChangeCell = Cells(12, 3).Address() & ":" & Cells(14, 3).Address()
ConstraintOne = Cells(12, 3).Address() & ":" & Cells(14, 3).Address()
ConstraintTwo = Cells(12, 3).Address() & ":" & Cells(14, 3).Address()
ConstraintThree = Cells(15, 3).Address()
ConstraintFour = Cells(17, 3).Address()

SolverReset
SolverOk SetCell:=ObjCell, MaxMinVal:=3, ValueOf:=Target_Return, ByChange:=ChangeCell
SolverAdd CellRef:=ConstraintOne, Relation:=3, FormulaText:="1"
SolverAdd CellRef:=ConstraintTwo, Relation:=3, FormulaText:="0"
SolverAdd CellRef:=ConstraintThree, Relation:=2, FormulaText:="1"
SolverAdd CellRef:=ConstraintFour, Relation:=2, FormulaText:=Plan_Duration

SolverOptions MaxTime:=1000, Iterations:=10000, Precision:=0.0000000001, _
AssumeLinear:=False, StepThru:=False, Estimates:=1, Derivatives:=1, _
SearchOption:=1, IntTolerance:=0.000000000001, Scaling:=False, Convergence:= _
0.0000000001, AssumeNonNeg:=False

SolverSolve UserFinish:=True
SolverFinish keepFinal:=1

End Sub
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Jon Peltier

MrExcel MVP
Joined
May 14, 2003
Messages
4,943
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Try to rearrange the order of the Solver calls. This may not help you much, but Solver can be flaky, and in a recent project, after weeks of frustration, it worked for us. This is the order we settled on:

SolverOptions
SolverReset
SolverAdd (all of them here)
SolverOk
SolverSolve

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 

Watch MrExcel Video

Forum statistics

Threads
1,122,556
Messages
5,596,820
Members
414,104
Latest member
imamalidadashzada

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top