Dear All,
We are writing a macro that generates some parameter distributions in one spreadsheet (Parameters), pastes them in another sheet called (Derivatives), runs the solver and then should take the optimal solution onto a third sheet called PSA.
The problem is that the macro runs but keeps copying the same values onto PSA. Moreover, we don't see that the optimal value changes when the macro is running.
Do you know what this is happening and how we could fix it? The macro below runs, but just doesn't update the optimal values and gives us a column with the same value in the final spreadsheet. We looked over all the threads and we can't pin down what to do with this.
Many thanks.
sabinemaria
The code is:
Sub test()
'
' test Macro
'
Sheets("Parameters").Select
Dim Index
Dim Trials
Index = 0
Trials = 10
Do
Sheets("Parameters").Select
Range("D1").Select
ActiveCell.FormulaR1C1 = "1"
Application.DisplayStatusBar = True
Range("E7:E27").Select
Selection.Copy
Sheets("Derivatives").Select
Range("C15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F13").Select
ActiveCell.FormulaR1C1 = "10"
Range("F14").Select
SolverReset
SolverAdd CellRef:="$F$11", Relation:=1, FormulaText:="80000"
SolverAdd CellRef:="$F$11", Relation:=3, FormulaText:="0"
SolverOk SetCell:="$B$4", MaxMinVal:=1, ValueOf:=0, ByChange:="p1_", Engine:=1 _
, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverSave saveArea:=Range("$R$1")
Range("$F$11").Select
Selection.Copy
Sheets("PSA").Select
Range("B4").Select
ActiveCell.Offset(Index, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
SolverFinish KeepFinal:=2
Sheets("Parameters").Select
Range("D1").Select
ActiveCell.FormulaR1C1 = "0"
Index = Index + 1
Loop While Index < Trials
End Sub
Bookmarks