+ Reply to Thread
Results 1 to 2 of 2

Goal seek limits

Hybrid View

  1. #1
    Registered User
    Join Date
    08-18-2015
    Location
    Bangladesh
    MS-Off Ver
    2010
    Posts
    20

    Goal seek limits

    Hey all,

    I have a macro that does an automatic goal seek in a specified range. For some occasions, the results are obvious nonsense, so I wanted to add limits to the function. Is there an easy way to do this?

    See Code below.

    Thanks
    Sub GoalSeek1()
    Dim ARange As Range, TRange As Range, Aaddr As String, Taddr As String, NumEq As Long, i As Long, j As Long
    Dim TSheet As String, ASheet As String, NumRows As Long, NumCols As Long
    Dim GVal As Double, Acell As Range, TCell As Range, Orient As String
    
        Aaddr = Range("E42").Value
        Taddr = Range("E41").Value
    
        On Error GoTo NoSheetNames
        ASheet = Range("C42").Value
        TSheet = Range("C41").Value
    
    NoSheetNames:
        On Error GoTo ExitSub
        If ASheet = Empty Or TSheet = Empty Then
            Set ARange = Range(Aaddr)
            Set TRange = Range(Taddr)
        Else
            Set ARange = Worksheets(ASheet).Range(Aaddr)
            Set TRange = Worksheets(TSheet).Range(Taddr)
        End If
    
        NumRows = ARange.Rows.Count
        NumCols = ARange.Columns.Count
    
        GVal = Range("G41").Value
               
        For j = 1 To NumCols
            For i = 1 To NumRows
                TRange.Cells(i, j).GoalSeek Goal:=GVal, ChangingCell:=ARange.Cells(i, j)
            Next i
        Next j
        End If
        
    ExitSub:
    End Sub
    Last edited by JesMath; 08-19-2015 at 09:50 AM.

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

    Re: Goal seek limits

    This forum can be strict about using code tags around code, so I would suggest that you edit your post accordingly (instructions for adding code tags are in the FAQ's).

    This is one of the reasons I don't use the Goal Seek utility very often. I prefer to use the Solver utility, which allows you to add constraints on decision variables or on the objective function or other cells in the spreadsheet. I would suggest that you become familiar with using Solver for your particular model, then learn how to call Solver from VBA.
    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. [SOLVED] Seeking Goal without using Goal Seek
    By Doc Science in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-07-2015, 02:24 PM
  2. Replies: 3
    Last Post: 07-27-2012, 01:44 PM
  3. 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
  4. Goal Seek Formula But Not Using Goal Seek
    By cady923 in forum Excel General
    Replies: 1
    Last Post: 08-05-2011, 03:53 PM
  5. Goal seek
    By tom1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2009, 02:35 PM
  6. about goal seek
    By hassan barjini in forum Excel General
    Replies: 1
    Last Post: 04-27-2006, 06:55 PM
  7. [SOLVED] Goal Seek
    By Jake in forum Excel General
    Replies: 1
    Last Post: 06-12-2005, 12:55 AM

Tags for this Thread

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