Skip to content

Instantly share code, notes, and snippets.

@JackDunnNZ
Created July 7, 2015 15:47
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/d29684f1a97a64ccd946 to your computer and use it in GitHub Desktop.
Save JackDunnNZ/d29684f1a97a64ccd946 to your computer and use it in GitHub Desktop.
Building variable range incrementally using OpenSolver API
Sub Test()
Set TestSheet = Sheets("Test")
OpenSolver.ResetModel TestSheet
AddVariables Range("A2"), TestSheet
AddVariables Range("B3"), TestSheet
End Sub
Sub AddVariables(VariableRange As Range, Sheet As Worksheet)
Dim CurrentVariables As Range
Set CurrentVariables = OpenSolver.GetDecisionVariablesWithDefault(Sheet)
Dim NewVariables As Range
If CurrentVariables Is Nothing Then
Set NewVariables = VariableRange
Else
Set NewVariables = Union(CurrentVariables, VariableRange)
End If
OpenSolver.SetDecisionVariables NewVariables, Sheet
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment