Create own function performing GoalSeek calculations

altren

New Member
Joined
May 28, 2010
Messages
4
I'm trying to write a function that adjusts a parameter using GoalSeek with the "setCell", "changingCell" and "Goal" as input parameters:

Code:
Function Adjust (SetCell As Range, GoalValue As Double, ChangingCell As Range) As Boolean
   Adjust = SetCell.GoalSeek(GoalValue, ChangingCell)
End Function

However, the above function simply returns "FALSE" and no GoalSeek calculations are performed :confused:. When I do the exact same thing with Excel's standard Goal Seek inputbox, it works. I have checked that SetCell.Address, ChangingCell.Address and GoalValue correspond to the input values I use in the standard inputbox.

Any clues on why this doesn't work? Many thanks in advance!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Functions cannot do these kind of things.

Most of the time, they can only return a value (boolean, text, number, ...) or return a message box.

As opposed to executing a method like GoalSeek.

Wim
 
Upvote 0
Thanks for your response!

The (working) solution I used before was a loop that performed GoalSeek calculations on a range of cells. The reason I wanted to put the GoalSeek method in a function is that I don't want the user to have to press a button to get the calculations done, but rather have the cells updated automatically when the input values change.

Can I do this in some other way?
 
Upvote 0
Then you could use a Worksheet_Change event that will fire on changing certain cells.

You can put it in the function, which is called during the event, to capture the True or False result. If the result would be False (as the result of some kind error), you could take additional steps. If it's True, you just continue.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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