Skip to content

Instantly share code, notes, and snippets.

@JackDunnNZ
Last active May 5, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackDunnNZ/c4eda47f3dfda205274553b4b3b3f057 to your computer and use it in GitHub Desktop.
Save JackDunnNZ/c4eda47f3dfda205274553b4b3b3f057 to your computer and use it in GitHub Desktop.
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