Goal Seek Macro

keanek

New Member
Joined
Jul 15, 2002
Messages
2
I am trying to create a macro that allows a cell reference to be used for the "To Value" field in Goal Seek. I have created the code, but it will only work if I put a number value in for the "To Value." If this can't be done, is there a macro I can create to set an equation equal to a referenced cell by changing another parameter? I'd like to make it so that the spreadsheet user for my particular program does not have to go through the Goal Seek process every time the data is changed. If anyone could please help I would appreciate it. Thank you.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

Here is one example, placed in the change event of the worksheet module:
---------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 2 And Target.Column = 2 Then
Range("C5").GoalSeek Goal:=Range("B5").Value, _
ChangingCell:=Range("C2")
End If
End Sub
----------------------------------------
Any time cell B2 is changed (target row and column = 2), the goal seek procedure is triggered, setting cell C5 to equal cell B5 by changing cell C2.

HTH,
Jay
 
Upvote 0
Hi,
I tried using this:

Here is one example, placed in the change event of the worksheet module:
---------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 2 And Target.Column = 2 Then
Range("C5").GoalSeek Goal:=Range("B5").Value, _
ChangingCell:=Range("C2")
End If
End Sub
----------------------------------------
Any time cell B2 is changed (target row and column = 2), the goal seek procedure is triggered, setting cell C5 to equal cell B5 by changing cell C2.
.............
When I change a parameter that causes the value in B5 to change, the resulting value in C5 does not perform the Goal Seek operation correctly to match this value. Am I doing something wrong? The cell B2 serves only to trigger the procedure correct?

Thanks.
 
Upvote 0
Hi,

Correct. You have to change the references to suit your data. If you are still having trouble after changing the references, please post some details so that we can see the problem.

Bye,
Jay
 
Upvote 0
Jay, can you explain how to use this goal seek function if a number changes on a worksheet outside of the one we are modifying? I.e., how do you reference a range of cells as target cells from a different sheet?
 
Upvote 0
Very good tip! Worked perfectly for me. Is there someway to change it so it actualizes automatically when a cell in another sheet changes?

Thx
 
Upvote 0

Forum statistics

Threads
1,214,422
Messages
6,119,396
Members
448,891
Latest member
tpierce

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