Help with code for Goal Seek

LSB M

New Member
Joined
Aug 17, 2012
Messages
6
Hi, I have the following code, but it doesn't work!


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Row = 15 And Target.Column = 9 Then
Range("M40").GoalSeek Goal:=0, ChangingCell:=Range("M38")
Range("M51").GoalSeek Goal:=0, ChangingCell:=Range("M49")
End If
End Sub

--
Basically I have a drop down bar in cell R15C9, everytime that cell changes, I want Goal Seek to automatically make 2 calculations, one is to change M38 so that M40=0, and the other is to change M49 so that M51=0.

Somehow the code above isn't working for me. Any idea why?

Thanks in advance for any help you can give!
 
Last edited:
If you're description is correct, you have M49 and M51 reversed in your code.

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address = "$I$15" Then
        Range("M40").GoalSeek Goal:=0, ChangingCell:=Range("M38")
        Range("M49").GoalSeek Goal:=0, ChangingCell:=Range("M51")
    End If
End Sub
 
Upvote 0
OK.

What happen when the code runs? Is M40 dependent on M38? Does it work from the UI?
 
Upvote 0
Cell R15C9 has three selections (3 different scenarios which, using the choose function, is fed into the calculations to spit out the P&L).

When I change cell R15C9, values update. With the above code, I had hoped that M38 and M49 would change too but basically nothing happens (the values in M38 and M49 stays the same with each different selections made in cell R15C9).

M40 is dependent on M38; and M51 is dependent on M49.
 
Upvote 0
Does the goalseek work when you do it from the user interface?

EDIT: BTW, the code works fine for me.
 
Last edited:
Upvote 0
Sorry, I'm a newbie when it comes to macros and VBA. When you say User Interface, what do you mean?

I tried to debug using the "Step Into" function ("F8") but I just get a "beep" when I do that. And when I try to Run the Sub ("F5"), I don't even see the macro listed in the pop up box.

Pretty confusing...
 
Upvote 0
Data > What-If Analysis > Goal-Seek...
 
Upvote 0
I don't have a suggestion -- as I said, the code works for me. If you want to post a workbook where you cross-posted, I'll look at it.

(And if you're going to cross-post, please have the courtesy to post a link to the other forums on each forum.)
 
Upvote 0

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