Solver macro Help Please!

jjb13

New Member
Joined
Aug 27, 2006
Messages
1
I am invoking solver within a macro. The first time that I ran the macro solver worked fine and I got a legitimate answer. I reset the changed cells again and ran the macro a second time, and it seemed to violate one of my constraints. I opened solver right from excel and saw that it hadn't even added the constraint the second time, even though it is clearly there in the VBA script!
Here is the macro:
Sub Defense()
'
' Defense Macro
' Macro recorded 8/27/2006 by
'

'
SolverReset
SolverOk SetCell:="$S$3", MaxMinVal:=1, ValueOf:="0", ByChange:="$P$5:$P$38"
SolverAdd CellRef:="$D$5:$F$38", Relation:=5, FormulaText:="binary"
SolverAdd CellRef:="$D$3:$F$3", Relation:=2, FormulaText:="$D$2:$F$2"
SolverAdd CellRef:="$Q$5:$Q$38", Relation:=1, FormulaText:="1"
SolverOk SetCell:="$S$3", MaxMinVal:=1, ValueOf:="0", ByChange:="$P$5:$P$38"
SolverOptions MaxTime:=10000, Iterations:=30000, Precision:=0.000001, _
AssumeLinear:=True, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption _
:=1, IntTolerance:=0, Scaling:=False, Convergence:=0.01, AssumeNonNeg:=True
SolverOk SetCell:="$S$3", MaxMinVal:=1, ValueOf:="0", ByChange:="$P$5:$P$38"
SolverSolve
End Sub

The bolded line is the one that is missing when I open solver, and it is the same whether I make that the first, second or third constraint. Again, it works fine the first time, but thereafter it refuses to add this constraint.

Any ideas?

thanks
JB
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I am having exactly the same problem and it's driving me crazy!!! Did you manage to find a solution?? Solver won't add the binary constraint (or indeed the integer constraint) when driven by VBA.

Any help on this, from anyone would be much appreciated.
 
Upvote 0

Forum statistics

Threads
1,226,452
Messages
6,191,133
Members
453,642
Latest member
jefals

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top