PDA

View Full Version : Solving a problem within VBA without using solver



xodus8
03-23-2011, 12:16 PM
Is there any way to solve a problem within VBA without actually calling the excel solver function ? For example

f (a,b,c,d) = a^(1/2) + b^(1/3)+c^(1/4)+d(1^5)-5

f(a,b,c,d) should be 0 by changing the parameters a,b,c,d.

I know this can be done using solver, but I can not figure out the logic within VBA.

Thanks

Kenneth Hobs
03-23-2011, 12:49 PM
Of course this only changes the one parameter in column A. The formula is in column H. The goal in your case would be 0.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Long
If Target.Count > 1 Or Target.Column <> 10 Then Exit Sub
r = Target.Row
Application.EnableEvents = False
On Error Resume Next
Range("H" & r).GoalSeek Goal:=Range("I" & r).Value, ChangingCell:=Range("A" & r)
Application.EnableEvents = True
End Sub