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

VBA Code for solver constraint not effective

Status
Not open for further replies.

CardinalKid

Industrial
Joined
Dec 4, 2007
Messages
1
Location
US
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?
 
CardinalKid,

Code:
Sub test()

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top