Vba 带解算器的循环
我正试图用解算器编程一个循环Vba 带解算器的循环,vba,loops,excel,solver,Vba,Loops,Excel,Solver,我正试图用解算器编程一个循环 Sub SharpeRatio() SolverReset SolverOk SetCell:="$Q$18", MaxMinVal:=1, ValueOf:="0", ByChange:="$L$18,$M$18", Engine:=1, EngineDesc:="GRG Nonlinear" SolverAdd CellRef:="$L$18", Relation:=3, FormulaText:="0" Solv
Sub SharpeRatio()
SolverReset
SolverOk SetCell:="$Q$18", MaxMinVal:=1, ValueOf:="0", ByChange:="$L$18,$M$18", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$L$18", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$L$18", Relation:=1, FormulaText:="1"
SolverAdd CellRef:="$M$18", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$18", Relation:=1, FormulaText:="1"
SolverAdd CellRef:="$R$18", Relation:=2, FormulaText:="1"
SolverSolve UserFinish:=True
End Sub
解算器代码可以工作。我需要优化Q列中的所有单元格,同时使用每个行中的值的约束。我需要对第14到2843行执行此操作
我似乎无法进入正确的循环。我应该如何重写它?我会将中的“$Letter$18”
更改为类似“$Letter”+I
的内容,然后将代码封装在for循环中
适用于i=14至2843
解算集
SolverOk SetCell:=“$Q”+i,MaxMinVal:=1,ValueOf:=“0”,ByChange:=“$L”+i,$M”+i,Engine:=1,EngineDesc:=“GRG非线性”
SolverAdd CellRef:=“$L”+i,关系:=3,公式文本:=“0”
SolverAdd CellRef:=“$L”+i,关系:=1,公式文本:=“1”
SolverAdd CellRef:=“$M”+i,关系:=3,公式文本:=“0”
SolverAdd CellRef:=“$M”+i,关系:=1,公式文本:=“1”
SolverAdd CellRef:=“$R”+i,关系:=2,公式文本:=“1”
SolverSolve UserFinish:=True
下一步
按照这些思路应该会奏效