Hi,
I have the below VBA code, but I get an error when I pass the varRange variable to the range in SolverOk. My goal is to have the Variable Cells and the Constraints in Solver to have dynamic range.
Sub Solver3()
Dim lastRow As Long
Dim varRange As String
With ThisWorkbook.Sheets("Sheet11")
lastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
varRange = "D18:D" & lastRow
SolverReset
SolverOk SetCell:="$C$31", MaxMinVal:=2, ValueOf:=0, varRange, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:=varRange, Relation:=6, FormulaText:="AllDifferent"
SolverAdd CellRef:="$G$18", Relation:=2, FormulaText:="1"
SolverOk SetCell:="$C$31", MaxMinVal:=2, ValueOf:=0, varRange, _
Engine:=3, EngineDesc:="Evolutionary"
SolverOk SetCell:="$C$31", MaxMinVal:=2, ValueOf:=0, varRange, _
Engine:=3, EngineDesc:="Evolutionary"
SolverSolve userFinish:=True
End With
End Sub
Thanks,
Bookmarks