VBA Code for solver constraint not effective
VBA Code for solver constraint not effective
(OP)
Hi all, I'm trying to write a macro that will solve a couple hundred excel solver problems. I've made the file smaller for your convenience. The main problem is that when the macro is run, the constraint for a binary solution does not hold. Has anyone seen a problem like this?
RE: VBA Code for solver constraint not effective
CODE
counter = 1:
For i = 1 To 1
For j = 2 To 53
Sheets("DATA").Cells(14, j).Value = Sheets("DATA").Cells(counter, j).Value
Next j
counter = counter + 1
Worksheets("data").Activate
SolverReset
SolverOptions , 0.001
'adding constraints
SolverAdd "$B$12:$AY$12", 1, "1"
SolverAdd "$B$12:$AY$12", 3, "0"
' executing solver
Application.Run "SolverOK", "$BC$14", 2, 0, "$B$12:$AY$12"
SolverAdd "$B$12:$AY$12", 5, "binary"
SolverAdd "$B$12:$AY$12", 4, "integer"
SolverSolve True
Next i
End Sub
two observations
1. You do not have to use application.run just activate your worksheet prior to code. This may or not may speed up your code and does not really matter.
2.<-- Most Important For some reason you have to list binary and interger below your solverok line. Do not ask me why. But this seemed to work for me.(xl 2007)
Hope this helps
ck1999