VBA Code for Goal Seek to Run Automatically

srand

New Member
Joined
Jan 22, 2010
Messages
7
I have a couple of worksheets that have goal seek already performed on 20 target cells (for each worksheet). I did this manually, without a macro (since I'm absolutely horrible at all of this).

Now from what I can tell, I need a code to add to the worksheet module in order to make sure that the goal seek updates itself whenever I change a value in the formula of the target cell.

what IS that code?! I can't understand the codes some people have put up, so I have no idea what to do.

Target Cell: M21:M42
Changing Cells: N21: N42
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Okay I have a code but it doesn't work. What's wrong with it?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim bSuccess As Boolean
On Error Resume Next
bSuccess = Range("M21:M42").GoalSeek(0, Range("N21:N42"))
On Error GoTo 0
If Not bSuccess Then
MsgBox "Goal Seek Failed for Cell ""N21:N42""!"
End If
End Sub

I know it has something to do with the ranges but I don't know how to change it.
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("M21:M42")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.GoalSeek goal:=0, changingcell:=Target.Offset(, 1)
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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