Microsoft KB Archive/124096

= GoalSeek Method in VB Macro Returns the Wrong Answer =

Article ID: 124096

Article Last Modified on 8/15/2005

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0 for Macintosh

-



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.

