Multiple Goal Seek Script

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
I need a script which does multiple goal seek by changing value in one cell. Here is the script I am using for single goal seek.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 7 And Target.Column = 2 Then
Range("B14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("B12")
End If
End Sub

I want to add in the above script that does the following and so on:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 7 And Target.Column = 2 Then
Range("C14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("C12")
End If
End Sub
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
This is what I tried but only the first goal seek works.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 7 And Target.Column = 2 Then
Range("B14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("B12")
Range("C14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("C12")
End If
End Sub

I have in total 8 goal seek to incorporate in script.

Please suggest if you have any better ideas. Thanks.
 

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
I hope I am clear on my question. If you do not understand, please let me know. It is very important for me to get this done. Please help.
 

facethegod

Well-known Member
Joined
Aug 1, 2006
Messages
767
This is what I tried but only the first goal seek works.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 7 And Target.Column = 2 Then
Range("B14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("B12")
Range("C14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("C12")
End If
End Sub

I have in total 8 goal seek to incorporate in script.

Please suggest if you have any better ideas. Thanks.

Not sure.. but if the value in B8 depends on the value in B7 and C7 then try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 7 And (Target.Column = 2 Or Target.Column = 3) Then
Range("B14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("B12")
Range("C14").GoalSeek Goal:=Range("B8").Value, _
ChangingCell:=Range("C12")
End If
End Sub

HTH
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,315
Members
414,053
Latest member
Dual Showman

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
Top