tropics123
Board Regular
- Joined
- May 11, 2016
- Messages
- 85
Hi, looking for some help with this Solver VBA. Here's what I'm trying to do:
1) "Set Objective" is equal to the value in cell D3
2) "Value of" is equal to the value in cell D1
3) "By Changing Variable Cells" - this range in column D (starts on D4) changes according to the number of rows in column B
4) Solver results should only return integers in column D (I set the constraint = integer). This constraint range also changes when the "Changing Variable Cells" change.
Problem: I think the code for the changing range in column D is causing the issue but I don't know what to do to make it work.
Sheets("Sheet3").Select
SolverOptions MaxTime:=0, Iterations:=0, Precision:=0.0000000001, Convergence:= _
0.0001, StepThru:=False, Scaling:=True, AssumeNonNeg:=True, Derivatives:=1
SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
IntTolerance:=1, SolveWithout:=False, MaxTimeNoImp:=30
Dim Lr As Long
Lr = .Cells(.Rows.Count, 3).End(xlUp).Row 'Changing variables in column D by counting the last row in column C
SolverOk SetCell:="$D$3", MaxMinVal:=3, ValueOf:="$D$1", ByChange:= _
Range("D4:D" & Lr), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=Range("$D4:D" & Lr), Relation:=4, FormulaText:="integer"
SolverSolve
End With
End Sub
1) "Set Objective" is equal to the value in cell D3
2) "Value of" is equal to the value in cell D1
3) "By Changing Variable Cells" - this range in column D (starts on D4) changes according to the number of rows in column B
4) Solver results should only return integers in column D (I set the constraint = integer). This constraint range also changes when the "Changing Variable Cells" change.
Problem: I think the code for the changing range in column D is causing the issue but I don't know what to do to make it work.
Sheets("Sheet3").Select
SolverOptions MaxTime:=0, Iterations:=0, Precision:=0.0000000001, Convergence:= _
0.0001, StepThru:=False, Scaling:=True, AssumeNonNeg:=True, Derivatives:=1
SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
IntTolerance:=1, SolveWithout:=False, MaxTimeNoImp:=30
Dim Lr As Long
Lr = .Cells(.Rows.Count, 3).End(xlUp).Row 'Changing variables in column D by counting the last row in column C
SolverOk SetCell:="$D$3", MaxMinVal:=3, ValueOf:="$D$1", ByChange:= _
Range("D4:D" & Lr), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=Range("$D4:D" & Lr), Relation:=4, FormulaText:="integer"
SolverSolve
End With
End Sub
Last edited: