Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to release memory used by solver commands?

Status
Not open for further replies.

JensKKK

Technical User
May 8, 2007
119
GB
Problem: I get sometimes funny error messages in VBA (Excel) that VBA can't execute a simple command such as Cells(1,1).select when adding code to my existing script. I don't think that the error message is pointing in the right direction because there is nothing wrong with the above descript command and this command was previously executed before adding more code to my existing script.

I am using the solver add in my program and I was wondering if that will use up a lot of memory and I want to make sure that I release the memory properly. The solver is called several 1000 times in this routine and it could possibly produce a big mess if it does release the memory correctly. Which in turn the throws up error messages that VBA can't execute the above mentioned Cells(1,1).select command.


Code example

'Open solver library
Application.Run "Solver.xla!Auto_Open"

'Clear solver contraints
SOLVERReset


For i=1 to 100
'Set solver contraints
SolverAdd CellRef:="$H$114", Relation:=1, FormulaText:="$H$103"
SolverAdd CellRef:="$H$119", Relation:=3, FormulaText:="$H$103"
'Call solver and calculate result

SolverOk SetCell:="$H$101", MaxMinVal:=2, ValueOf:="0", ByChange:="$H$103"
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1

'reset solver after the job is done

SOLVERReset

NEXT
' close solver library
Application.Run "Solver.xla!Auto_Close"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top