M
Mike
Hi everyone,
I have this simple 3 subs vba code. It runs 8 times and each solution
has 24 values that is put in one column of 24 raws. So, the 1st
solution found gets written at N2 to N25....and so on.
The problem I have is this: The 1st solution that gets written from
N2-N25, later it gets removed; just the 1st solution! What could be
causing this in the code? Thanks in advance.
Option Explicit
Option Base 1
Sub Pareto()
Dim cell As Range, ModelCounter As Integer, JobNr As Integer
Dim ret As Integer
Dim ARngSolution As Range
Application.ScreenUpdating = False
ModelCounter = 0
Set ARngSolution = Range("SolDVSens")
ARngSolution.ClearContents
For JobNr = 1 To 8
ret = SolverSolve(UserFinish:=True)
If ret = 0 Or ret = 14 Then
ModelCounter = ModelCounter + 1
RunSolver
StoreResults ModelCounter
End If
Next
End Sub
Sub RunSolver()
SolverReset
SolverOk SetCell:=Range("Obj2"), MaxMinVal:=1,
ByChange:=Range("Picked")
SolverAdd CellRef:=Range("Spending"), Relation:=1,
FormulaText:="Budget"
SolverAdd CellRef:=Range("Picked"), Relation:=5
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
End Sub
Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range("N1")
For i = 1 To 24
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With
End Sub
I have this simple 3 subs vba code. It runs 8 times and each solution
has 24 values that is put in one column of 24 raws. So, the 1st
solution found gets written at N2 to N25....and so on.
The problem I have is this: The 1st solution that gets written from
N2-N25, later it gets removed; just the 1st solution! What could be
causing this in the code? Thanks in advance.
Option Explicit
Option Base 1
Sub Pareto()
Dim cell As Range, ModelCounter As Integer, JobNr As Integer
Dim ret As Integer
Dim ARngSolution As Range
Application.ScreenUpdating = False
ModelCounter = 0
Set ARngSolution = Range("SolDVSens")
ARngSolution.ClearContents
For JobNr = 1 To 8
ret = SolverSolve(UserFinish:=True)
If ret = 0 Or ret = 14 Then
ModelCounter = ModelCounter + 1
RunSolver
StoreResults ModelCounter
End If
Next
End Sub
Sub RunSolver()
SolverReset
SolverOk SetCell:=Range("Obj2"), MaxMinVal:=1,
ByChange:=Range("Picked")
SolverAdd CellRef:=Range("Spending"), Relation:=1,
FormulaText:="Budget"
SolverAdd CellRef:=Range("Picked"), Relation:=5
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
End Sub
Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range("N1")
For i = 1 To 24
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With
End Sub