找不到名称参数

时间:2018-06-05 04:45:46

标签: excel vba excel-vba solver

当我运行以下代码时,Name argument not found将出现错误“SetCell:="$I$3"”。

Sub Simple_Exponential_Smoothing()
    Dim x As Integer
    Dim lastrow As Integer
    Application.ScreenUpdating = False
    Sheets("COV_0.2").Cells(1, 49).Value = "MAD"
    Sheets("COV_0.2").Cells(1, 50).Value = "Alpha"
    lastrow = Sheets("COV_0.2").Cells(Rows.Count, 2).End(xlUp).Row
    For x = 2 To lastrow
        If Sheets("COV_0.2").Cells(x, 31).Value <> "S4" Then
            Range("G" & x & ":AD" & x).Select
            Selection.Copy
            Sheets("Analysis_Constant").Select
            Range("C4").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=True
            Application.Run "Solver.xlam!SolverReset"

   '***ERROR ON THE FOLLOWING LINE: `Name argument not found`
            Application.Run "Solver.xlam!SolverOk", SetCell:="$I$3", _
                MaxMinVal:=2, ValueOf:=0, ByChange:="$G$1", Engine:=3, _
                EngineDesc:="Evolutionary"

            Application.Run "Solver.xlam!SolverAdd", CellRef:="$G$1", _
                Relation:=1, FormulaText:="0.9"
            Application.Run "Solver.xlam!SolverAdd", CellRef:="$G$1", _
                Relation:=3, FormulaText:="0.1"
            SolverSolve True

1 个答案:

答案 0 :(得分:0)

您必须在工具/参考中设置对Solver插件的引用:

  1. 从Excel VBA编辑器窗口的“工具”菜单中选择“参考”。
  2. 选中“解算器”复选框。
  3. 单击“确定”。
  4. 然后正确的Solver语法是:

    SolverReset
    
    SolverOk SetCell:="$I$3", _
        MaxMinVal:=2, ValueOf:=0, ByChange:="$G$1", Engine:=3, _
        EngineDesc:="Evolutionary"
    
    SolverAdd CellRef:="$G$1", Relation:=1, FormulaText:="0.9"
    SolverAdd CellRef:="$G$1", Relation:=3, FormulaText:="0.1"
    SolverSolve True