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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solver & VBA

Status
Not open for further replies.

ferbg

Technical User
Mar 29, 2002
7
IT
Hi,

I have this problem: I need to make interact the macro of my program with the solver function of Excel. If I launch the solver, as I normally do from the Tools menu, the macro is not runned, so I tried to run the solver function using the following sintax:

The sub Losses Estimation is called by a button in the Excel spreadsheet.

-----------------
Sub Losses_Estimation()

'Clear any previous Solver settings
SolverReset

'Set up the parameters for the model:
SolverOk SetCell:=Range("n37"), maxMinVal:=2, ByChange:=("c28,g11,AMAIN()")

'Add the constraints for the model.
SolverAdd CellRef:=Range("g11"), relation:=3, FormulaText:=45
SolverAdd CellRef:=Range("g11"), relation:=1, FormulaText:=70
SolverAdd CellRef:=Range("c28"), relation:=1, FormulaText:=g21

'Display the Solver Results dialog
SolverSolve

'Finish and keep the final results
SolverFinish KeepFinal:=1

End Sub


This subroutine performs the calculations

Sub AMAIN()

With Worksheets(3)


PI = 3.1415926
PI2 = PI * 2
N = 101 ' NUMBER OF POINTS IN FI - DIRECTION

'
' GET DATA FOR VANELESS DIFFUSER
'
RO2 = .Cells(12, 3).VALUE
C2 = .Cells(33, 3).VALUE
ALP2 = .Cells(36, 3).VALUE



etc,etc
--------------------
The scope is that at each step of the solver iteration the sub AMAIN() should be called and runned.

I don't know how to write the code to get this interaction between the solver and the sub AMAIN().
I hope I've well explained the problem, thanks in advance.

Fernando
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top