View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Catching max iterations Stop of Solver in VBA

"REASON" as a case variable. In case when the reason =10, I do not
want the dialog box to show at all -- instead it should take the option


Hi. I believe you meant when the "Result" is 10...
10 indicates a Time limit was reached.
Don't feel too bad... This technique is not documented anywhere as far as I
know.

This "should" work ...

Sub Your_Main_Code()
Dim Results

' << YOUR MAIN SOLVER CODE HERE

SolverOptions Iterations:=10 'Your Value here
SolverOptions StepThru:=True
Results = SolverSolve(True, "SolverStepThru")

Select Case Results
Case 0, 1, 2
' Solver found a solution.
SolverFinish 1
Case 3, 10
SolverFinish 1 ' Keep Results, and move on...
End Select
End Sub

Function SolverStepThru(Reason As Integer)
Select Case Reason
Case 2, 3
SolverStepThru = True ' Will Abort
End Select
End Function

--
Dana DeLouis
Win XP & Office 2003


"msuryexcel" wrote
in message ...

Hi Dana:
I am sorry to say that I have tried the three responses you have given
on this problem and none of them seem to work for me.

Simply stated: I have a VBA code that runs the solver in a loop.
Inside the loop there are situaitons when the solver reaches the MAX
TIME LIMIT (or MAX iterations). In understand your idea of using the
"REASON" as a case variable. In case when the reason =10, I do not
want the dialog box to show at all -- instead it should take the option
"STOP" and go to the next iteraiton of the loop. I am not able to do
this. I need help in writing the code that does something similar to
SolverSolve UserFinish:=True
Your idea of the
Function SolverStepThru(Reason As Integer)
did not work.
Any other suggestion or help will be greatly appreciated.

Thanks in advance
manda

Dana DeLouis Wrote:
Hi. Here is a general outline of the code. Good luck...

Sub DEMO()
Dim Results As Long

'...YOUR CODE to set Solver ...

Results = SolverSolve(True)

Select Case Results
Case 0, 1, 2
' Found a solution
' Yeah! Your code to continue...
SolverFinish KeepFinal:=True
Case 3
' Stop chosen when the maximum iteration limit was reached.
' Your code here??
Case 10
' Stop chosen when the maximum time limit was reached.
' Your code here...
Case 7
' The conditions for Assume Linear Model are not satisfied.
' Your code to Un-select this option, and try Solver again...
Case 4
' The Set Target Cell values do not converge.
' Keep count of this error. Perhaps use Random
' Initial values, and try Solver again.
Case Else
' Most likely an Error. :(
' Now what?
End Select

End Sub

HTH :)
--
Dana DeLouis
Win XP & Office 2003


"wgaskill" wrote in message
...
I would like to set up my macro so that if Solver does not converge

at
maximum iterations, the Solver dialog is not displayed, and the

macro
continues on with the best guess. Is there a way to turn off the

dialog
if
Solver doesn't converge?



--
msuryexcel
------------------------------------------------------------------------
msuryexcel's Profile:
http://www.excelforum.com/member.php...o&userid=28161
View this thread: http://www.excelforum.com/showthread...hreadid=483175