I would like to set up my macro so that if Solver does not converge at
Hi. You need an Aux function for that to work.
Here's part of a general outline that I use.
Sub Your_Main_Code()
Dim Results
Const Keep_Results = 1
Const Discard_Results = 2
Const AnswerReport = 1
' << ONE OF A FEW IMPORTANT CHECKS! >>
If InStr(1, ActiveWorkbook.Name, Space(1)) > 0 Then
MsgBox "IMPORTANT: Remove all SPACES from workbook name",
vbCritical
End
End If
' << 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.
' Keep final values & generate answer report
SolverFinish KeepFinal:=Keep_Results,
ReportArray:=Array(AnswerReport)
Case 3
'Max Iterations was exceeded
SolverFinish Keep_Results ' OR Discard_Results
End Select
End Sub
Function SolverStepThru(Reason As Integer)
Const xContinue As Boolean = False 'Excel XP
Const xStopRunning As Boolean = True 'Excel XP
Select Case Reason
Case 3
'Max Iterations was exceeded
SolverStepThru = xStopRunning
End Select
End Function
Good luck. HTH. :>)
--
Dana DeLouis
Win XP & Office 2003
wgaskill said:
This code does not eliminate the Solver dialog box being displayed when
max
iterations is reached. Is there anything that can be done to NOT display
the
box that says "Max iterations have been reached"?
<snip>