Solved

Excel 2007 Goal Seek Formula

Posted on 2010-11-17
9
1,234 Views
Last Modified: 2012-06-27
Hello,

Please review the attached code.  The goal seek formula is making the adjustment in cell E64.  I need to set up a limit in which the amount in E64 that goal seek recommends should not be less than 0 or greater than the amount in cell I64.  If the amount does not fall within this parameter an error message appears stating "Amount Does Not Fall Within Required Parameters.  Please Try Again".

Any suggestions on how to make this happen?

Thanks!


Range("E74").GoalSeek Goal:=Range("H68"), ChangingCell:=Range("E64")

Open in new window

0
Comment
Question by:Escanaba
  • 4
  • 4
9 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158648
Range("E64").Value = WorksheetFunction.Median(0, Range("E64").Value, Range("I64").Value)
0
 
LVL 1

Author Comment

by:Escanaba
ID: 34158818
So for the entire string its this:
Range("E74").GoalSeek Goal:=Range("H68"), ChangingCell:=Range("E64").Value = WorksheetFunction.Median(0, Range("E64").Value, Range("I64").Value)

If so its bugging stating reference not valid.
0
 
LVL 1

Author Comment

by:Escanaba
ID: 34158847
Here is the full code:

Private Sub CommandButton2_Click()
    With Application
       .DisplayAlerts = False
       .EnableEvents = False
       .ScreenUpdating = False
      Application.Calculation = xlCalculationManual
    End With
   
     
    Range("E74").GoalSeek Goal:=Range("H68"), ChangingCell:=Range("E64").Value = WorksheetFunction.Median(0, Range("E64").Value, Range("I64").Value)
   
   
    With Application
    .DisplayAlerts = True
    .EnableEvents = True
    .ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    End With
 
End Sub
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158894
No. My code was for after the value was put in E64. Like this: (You could use a different cell for the final value)
Range("E74").GoalSeek Goal:=Range("H68"), ChangingCell:=Range("E64")



Range("E64").Value = WorksheetFunction.Median(0, Range("E64").Value, Range("I64").Value)

Open in new window

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 80

Expert Comment

by:byundt
ID: 34158910
Solver can handle multiple constraints and changing cells, but Goal Seek requires a single criterion (minimum, maximum or specific value).

From the description of the problem, the final solution might be:
=MAX(0,MIN(I64,E64))                 the Goal Seek result should be between 0 and I64.

You would then run Goal Seek using E64 same as previously, then replace the value found by Goal Seek with the result of the MAX/MIN formula.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34158945
byundt, your answer is the same as mine except the median function does the min/max in one step.
0
 
LVL 1

Author Comment

by:Escanaba
ID: 34159037
Got it & thank you.  Any recommendations on the 2nd part of my original question regarding generating an error message so the end user knows they've exceeded the parameters?  As it stands, nothing updates which is good but doesnt tell them why.
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 34159083
Then you'd need something like this (and the median trick isn't as useful).
Range("E74").GoalSeek Goal:=Range("H68"), ChangingCell:=Range("E64")



If Range("E64").Value <0 Then

  MsgBox "Came out less than 0, changed to 0"

  Range("E64").Value = 0

End if

If Range("E64").Value > Range("I64").Value Then

  MsgBox "Came out greater than " & Range("I64").Value & ", changed to " & Range("I64").Value

  Range("E64").Value = Range("I64").Value

End If

Open in new window

0
 
LVL 1

Author Closing Comment

by:Escanaba
ID: 34159162
Appreciate the assistance.  Thank you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now