Solver programming questions
Hi
The syntax for a cell reference in VBA is :
Range($A$3")
I have never used the solver function, but I found this in the VBA help:
SolverSolve Function Example
This example uses the Solver functions to maximize gross profit in a
business problem. The SolverSolve function begins the Solver solution run.
Worksheets("Sheet1").Activate
SolverReset
SolverOptions Precision:=0.001
SolverOK SetCell:=Range("TotalProfit"), _
MaxMinVal:=1, _
ByChange:=Range("C4:E6")
SolverAdd CellRef:=Range("F4:F6"), _
Relation:=1, _
FormulaText:=100
SolverAdd CellRef:=Range("C4:E6"), _
Relation:=3, _
FormulaText:=0
SolverAdd CellRef:=Range("C4:E6"), _
Relation:=4
SolverSolve UserFinish:=False
SolverSave SaveArea:=Range("A33")Hopes this helps---Per"gvm"
skrev i meddelelsen
...
I created a macro that uses Solver by recording one, selecting solver as a
VBA reference, and changing the target value from a number to a cell
reference. In the spreadsheet, cell A3 = A1*A2. Cells A1 and A2 simply
contain values. C1 contains the number that Solver should use as the
target
value. Here's the macro code€¦
Sub Macro2()
'
' Macro2 Macro
SolverOk SetCell:="$A$3", MaxMinVal:=3, ValueOf:="C1", ByChange:="$A$2"
SolverSolve
End Sub
First problem is that the solver runs successfully on the first occasion
the
macro is run, but running the macro after changing the number in C1
creates
erroneous output. The reason seems to be that Solver contains target
number
from the first occasion. I think this because when I open the Solver
dialogue
box, it contains references from the first occasion. Is there a need for a
line of code that somehow resets Solver?
Second problem is I would like to modify the code to automatically accept
the output Solver finds, regardless of whether it succeeded in finding a
solution or not. How do I change the code to do that please?
Finally, the Solver constraints did not appear in the macro that was
recorded. Where can I find information about coding constraints into the
macro please? TIA €¦. Greg
|