View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Solver: 2nd function of SolverSolve

Hi. Place your code in a regular vba module. Then go to Tool | References
| and select Solver.
Note that there are documentation errors with this method. I can't find my
notes right now.
I think this method was messed up with a previous version of Excel.
However, it seems fixed with Excel XP & 2003.
I believe the correct method to end your ShowTrial function is with:

ShowTrial = False

The following is a very general outline of a solver macro. Hopefully, this
will give you some ideas for your own code.

SolverReset ' Clear everything.
' Set it up
SolverOk SetCell:="$C$11", MaxMinVal:=3, ValueOf:="130",
ByChange:="$C$4:$C$6"
' Add constraints...
SolverAdd CellRef:="$C$4:$C$6", Relation:=1, FormulaText:="$E$4:$E$6"
SolverAdd CellRef:="$C$4:$C$6", Relation:=3, FormulaText:="$D$4:$D$6"

' Previous documentation had errors here also...
' Set to True for ShowTrial
SolverOptions StepThru:=True

Results = SolverSolve(True, "ShowTrial")

' 0 Solver found a solution.
If Results = 0 Then SolverFinish True ' Or 1 or 2.

HTH. Good Luck. :)
--
Dana DeLouis
Win XP & Office 2003


"zaina" wrote in
message ...

Hello. New guy here so please be gentle. :)

From searching the internet, I've learned that the 2nd function of
SolverSolve can be called to count the number of iterations performed
by Solver, ie:

SolverSolve (1st_function, 2nd_function).


Here's the code I found, however I can not make it to run. Where do I
put the code in the VBA program? I mean what would be the complete
SolverSolve command?


Code:
--------------------
Global count as integer

Sub test()
count = 0
ret = solveroptions(stepthru:=True) '"checks" the Show Iteration checkbox
in Tools/Solver/Options
ret = solversolve(True, "showtrial")
MsgBox count
End Sub

Function showtrial(reason As Integer)
If reason = 1 Then 'reason = 1 means that the function will be called on
each iteration.
count = count + 1 'increments global variable
End If
showtrial = 1 ' continues Solver
End Function
--------------------


Thanks in advance!


--
zaina
------------------------------------------------------------------------
zaina's Profile:
http://www.excelforum.com/member.php...o&userid=24316
View this thread: http://www.excelforum.com/showthread...hreadid=379230