Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Problem with Goalseek Macro

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Problem with Goalseek Macro

Try this. (untested)..You can disable the events and then enable it once your
code executes....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Application.Intersect(Target, Range("D20") Is Nothing Then
Application.EnableEvents = False

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If

Application.EnableEvents = True
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ken G." wrote:

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Problem with Goalseek Macro

Thanks Jacob.

This line ..
If Not Application.Intersect(Target, Range("D20") Is Nothing Then
.... is giving a syntax error.

"Jacob Skaria" wrote:

Try this. (untested)..You can disable the events and then enable it once your
code executes....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Application.Intersect(Target, Range("D20") Is Nothing Then
Application.EnableEvents = False

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If

Application.EnableEvents = True
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ken G." wrote:

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Problem with Goalseek Macro

I fixed the syntax error but its still giving the same 1004 error message at
the same place saying the reference is invalid...

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")



"Jacob Skaria" wrote:

Try this. (untested)..You can disable the events and then enable it once your
code executes....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Application.Intersect(Target, Range("D20") Is Nothing Then
Application.EnableEvents = False

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If

Application.EnableEvents = True
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ken G." wrote:

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Problem with Goalseek Macro

The problem appeared to be that D56 contained a formula. I changed the macro
to do the calculation in D56 so that goalseek sees it is a value and it now
works.

"Jacob Skaria" wrote:

Try this. (untested)..You can disable the events and then enable it once your
code executes....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Application.Intersect(Target, Range("D20") Is Nothing Then
Application.EnableEvents = False

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If

Application.EnableEvents = True
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ken G." wrote:

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Problem with Goalseek Macro

Ken , good to hear it is working..

1. I missed thhe closing braces ...
2. The below line will make sure that the target is D20...
If Not Application.Intersect(Target, Range("D20")) Is Nothing Then


If this post helps click Yes
---------------
Jacob Skaria


"Ken G" wrote:

The problem appeared to be that D56 contained a formula. I changed the macro
to do the calculation in D56 so that goalseek sees it is a value and it now
works.

"Jacob Skaria" wrote:

Try this. (untested)..You can disable the events and then enable it once your
code executes....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Not Application.Intersect(Target, Range("D20") Is Nothing Then
Application.EnableEvents = False

Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If

Application.EnableEvents = True
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ken G." wrote:

I've written a macro in Excel 2003 to perform the goalseek function, but
there's a problem. In the code below I want F66 to be equal to D4 by changing
D61. If this causes D61 to go less than zero, then it gets set to zero and
the second goal seek comes into play this time changing cell D56.

I get an error message highlighting the second goal seek code saying error
code 1004, Invalid reference.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 20 And Target.Column = 4 Then
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D61")

If Range("D61").Value < 0 Then
Range("D61").Value = 0
Range("F66").GoalSeek Goal:=Range("D4").Value, _
ChangingCell:=Range("D56")
End If
End If

What am I doing wrong?

Its possible that I might need to extend this to set D56 to zero if it goes
under and run goalseek on another cell.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Excel Solver or Goalseek on multiple Sheets in a Workbook au AlfredR Excel Worksheet Functions 2 September 5th 07 10:06 AM
How do I set a goalseek value via an input box using vba macro TJK Excel Worksheet Functions 1 August 23rd 07 09:18 PM
Goalseek Excel 2007 Gerry Verschuuren Excel Discussion (Misc queries) 1 February 7th 07 11:12 AM
GoalSeek in VBA [email protected] Excel Discussion (Misc queries) 1 July 20th 06 05:13 AM
Goalseek / Solver Target Value msnews.microsoft.com Excel Worksheet Functions 1 December 2nd 05 01:41 PM


All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"