+ Reply to Thread
Results 1 to 7 of 7

Goal Seek in VBA

Hybrid View

JoeSkittles Goal Seek in VBA 12-20-2013, 12:40 PM
shg Re: Goal Seek in VBA 12-20-2013, 12:50 PM
JoeSkittles Re: Goal Seek in VBA 12-20-2013, 02:46 PM
shg Re: Goal Seek in VBA 12-20-2013, 02:53 PM
JoeSkittles Re: Goal Seek in VBA 12-20-2013, 03:00 PM
shg Re: Goal Seek in VBA 12-20-2013, 03:13 PM
MrShorty Re: Goal Seek in VBA 12-20-2013, 03:42 PM
  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Goal Seek in VBA

    Hello All,

    I'm trying to create a macro that will perform Goal Seek. I have the following code so far:
    Public Sub Goal_Seek()
    
    Application.Worksheets("Sheet3").Range("Test1").GoalSeek _
        Goal:=0, _
        ChangingCell:=Worksheets("Sheet3").Range("Test2")
    
    
    End Sub
    When I run it, however, I receive the "Run-time error '1004': Application-defined or object-defined error." Any help would be greatly appreciated.

    Thanks!
    Joe

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Goal Seek in VBA

    Are those both single-cell ranges? Does the result converge? Can you post a minimal workbook?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Goal Seek in VBA

    VBA Test.xlsm

    Here is a sample workbook. The ranges are both just single cells. Thanks!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Goal Seek in VBA

    Test1 is a constant; it has no dependency on the changing cell.

  5. #5
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Goal Seek in VBA

    However, cells C1 and D1 depend on Test1. I can perform Goal Seek normally in Excel (without using VBA), and Test1 becomes 16.66. So I don't think that's the issue.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Goal Seek in VBA

    The value in Test1, the GoalSeek cell (which is A1) is 1. That's a constant, not a formula; nothing you do in any other cell is going to change it.

    Sure you posted the right workbook?

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Goal Seek in VBA

    Or perhaps you meant to set the value of test2 (the cell that contains the formula) to a value of 0 by changing test1 (the input constant)?

    Application.Worksheets("Sheet3").Range("Test2").GoalSeek _
        Goal:=0, _
        ChangingCell:=Worksheets("Sheet3").Range("Test1")
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 07-27-2012, 01:44 PM
  2. Goal Seek VBA with relative 'Goal' parameter
    By alirulez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2012, 07:19 PM
  3. Goal Seek Formula But Not Using Goal Seek
    By cady923 in forum Excel General
    Replies: 1
    Last Post: 08-05-2011, 03:53 PM
  4. Goal Seek
    By craigafrica in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-26-2008, 11:33 AM
  5. Goal Seek
    By mangesh in forum Excel General
    Replies: 0
    Last Post: 04-26-2007, 06:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1