Multiple Automatic Goal Seek Macro

BHaselman

New Member
Joined
Oct 12, 2009
Messages
1
Hello,

I have a need to perform four separate goal seek fuctions in an excel chart. I have been attempting to create a macro that will automate all of these functions when I change a cell. I found this code online to automate one goal seek:
----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim bSuccess As Boolean
On Error Resume Next
bSuccess = Range("G18").GoalSeek(0, Range("C18"))
On Error GoTo 0
If Not bSuccess Then
MsgBox "Goal Seek Failed for Cell ""C18""!"
End If

End Sub
Sub GoalSeek()
End Sub
---------------------------------------------------------------------

This code works perfectly. However, I wanted to automate the goal seek function for three other cell-pairs. I created three other identical macros and simply changed the "Range" and "GoalSeek" values to match the other cells. (I also had to alter the "Worksheet_Change" name for each macro.)
I ran the macros and there were no error messages. However, when I change a cell value, only the first goal seek function is automated.

Any suggestions on how to automate all of the goal seek functions at once would be greatly appreciated
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You need to incorporate all 4 into one macro. You can do this by testing the .address property of 'target and building a select .. case to apply the slightly different criteria, as in:

select case target.address
case "$A1"
'code for this case goes here
case "$A2"
'etc
end select

HTH
 
Upvote 0
I implemented as below, but it's not working. Any advice?

Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo TheEnd
Select Case Target.Address
Case "G10"
If Target.Address = "$F$10" Then
Application.EnableEvents = False
Range("G16").GoalSeek Goal:=Range("F16").Value, _
ChangingCell:=Range("G10")
End If
Select Case Target.Address
Case "I10"
If Target.Address = "$F$10" Then
Application.EnableEvents = False
Range("I16").GoalSeek Goal:=Range("F16").Value, _
ChangingCell:=Range("I10")
End If
End Select
End Select
TheEnd:
Application.EnableEvents = True
End Sub
 
Upvote 0
Could you post sample workbook using Megaupload?
 
Upvote 0
I found the solution. The code below will automatically run two instances of goal seek whenever cell I15 changes.

Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo TheEnd
If Target.Address = "$I$15" Then
Application.EnableEvents = False
Range("H20").GoalSeek Goal:=Range("G20").Value, _
ChangingCell:=Range("H16")
Range("J20").GoalSeek Goal:=Range("G20").Value, _
ChangingCell:=Range("J16")
End If
TheEnd:
Application.EnableEvents = True
End Sub
 
Upvote 0
Could you please post sample file using Megaupload so I can see your example?
 
Upvote 0
Just zip the file and use mega upload and paste the link.

Thank you.
 
Upvote 0
It is possible to make very simple example? Very keen to seen your method in action.

Biz
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top