Skip to content

Instantly share code, notes, and snippets.

Last active May 5, 2016 13:02
What would you like to do?
Example of constructing a model with OpenSolver API
Option Explicit
Function Test()
Dim Sheet as Worksheet
Set Sheet = ThisWorkbook.Sheets("Sheet1")
OpenSolver.ResetModel Sheet
OpenSolver.SetDecisionVariables Sheet.Range("D4:F4"), Sheet
OpenSolver.SetObjectiveFunctionCell Sheet.Range("H6"), Sheet
OpenSolver.AddConstraint Sheet.Range("H8:H9"), RelationLE, Sheet.Range("J8:J9"), sheet:=Sheet
OpenSolver.AddConstraint Sheet.Range("H10"), RelationGE, Sheet.Range("J10"), sheet:=Sheet
OpenSolver.AddConstraint Sheet.Range("H11"), RelationEQ, Sheet.Range("J11"), sheet:=Sheet
OpenSolver.RunOpenSolver sheet:=Sheet
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment