NamedRange.GoalSeek Method

Calculates the values necessary to achieve a specific goal.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)


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


  • Goal
    Type: System.Object
    The value you want returned in this cell.

Return Value

Type: System.Boolean
true if the goal seek is successful; otherwise, false.


If the goal is an amount returned by a formula, this calculates a value that, when supplied to your formula, causes the formula to return the number you want.


The following code example sets a formula in a NamedRange control, and then uses the GoalSeek method to determine which value for X in the formula will return the value 15. The example places the answer in cell B1.

This example is for a document-level customization.

    Private Sub FindGoal()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1"), _

        Me.Range("B1").Name = "X"
        namedRange1.Formula = "=(X^3)+(3*X^2)+6"
        namedRange1.GoalSeek(15, Me.Range("B1"))
    End Sub

private void FindGoal()
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", missing],

    this.Range["B1", missing].Name = "X";
    namedRange1.Formula = "=(X^3)+(3*X^2)+6";
    namedRange1.GoalSeek(15, this.Range["B1", missing]);

.NET Framework Security

See Also


NamedRange Interface

Microsoft.Office.Tools.Excel Namespace