Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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