GoalSeek Method in VB Macro Returns the Wrong Answer (124096)
The information in this article applies to:
- Microsoft Excel for Windows 95
- Microsoft Excel for Windows 5.0
- Microsoft Excel for the Macintosh 5.0
This article was previously published under Q124096 SYMPTOMS
The GoalSeek method in Visual Basic for Applications may return an answer
that is different from the one returned by the Goal Seek command on the
Tools menu. The correct answer is the one returned when you choose Goal
Seek from the Tools menu.
WORKAROUND
If the GoalSeek method does not return the correct answer, use the
Application.ExecuteExcel4Macro command to run the Microsoft Excel 4.0
GOAL.SEEK macro command.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following example sets cell A1 to the value 15 by changing cell B1.
Example- Type the following into a worksheet:
A1: =(B1^3)+(3*B1^2)+6 B1: (blank) - In a module sheet, type the following:
Sub Test()
Application.ExecuteExcel4Macro "GOAL.SEEK(""r1c1"",15,""r1c2"")"
End Sub
If you want the second parameter (the "To Value" parameter) to refer to
a specific cell (D1, for example) on the worksheet, rather than a fixed
value, use the following syntax:
Application.ExecuteExcel4Macro "GOAL.SEEK(""r1c1""," & _
Range("D1").Value & ",""r1c2"")"
This example assumes that the number 15 has been entered in cell D1.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. We are researching this problem
and will post new information here in the Microsoft Knowledge Base as it
becomes available.
REFERENCES
"User's Guide," version 5.0, Chapter 6, "Seeking a Value That Solves a
Formula"
For more information about the GoalSeek Method, choose the Search button in
Visual Basic Reference Help, and type the following:
Modification Type: | Minor | Last Reviewed: | 8/15/2005 |
---|
Keywords: | kbbug kbcode kbProgramming KB124096 |
---|
|