XmlMappedRange.GoalSeek 方法

计算实现特定目标所必需的值。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Function GoalSeek ( _
    Goal As Object, _
    ChangingCell As Range _
) As Boolean
bool GoalSeek(
    Object Goal,
    Range ChangingCell
)

参数

  • Goal
    类型:System.Object
    希望在此单元格中返回的值。

返回值

类型:System.Boolean
如果目标查找成功,则为 true;否则为 false。

备注

如果目标值是由某个公式返回的数量,则这会计算一个值,如果将该值提供给您的公式,则将导致该公式返回所需的数字。

示例

下面的代码示例使用 GoalSeek 方法查找 27 的立方根,并将答案放置在单元格 A1 中。 此代码示例假定当前工作表包含一个名为 CustomerAddress1Cell 的 XmlMappedRange,并且它具有类型为 int 的相应架构元素。

Private Sub SolveFormula()
    Me.CustomerAddress1Cell.Formula = "=(A1^3)"
    Me.CustomerAddress1Cell.GoalSeek(27, Me.Range("A1"))
End Sub
private void SolveFormula()
{
    this.CustomerAddress1Cell.Formula = "=(A1^3)";
    this.CustomerAddress1Cell.GoalSeek(27, this.Range["A1", missing]);
}

.NET Framework 安全性

请参见

参考

XmlMappedRange 接口

Microsoft.Office.Tools.Excel 命名空间