View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Problems with solver and vba


-----Original Message-----
look at
http://support.microsoft.com/default.aspx?

scid=/support/excel/content/solver/solver.asp

"


.


To be honest i just tried to make the axample work before
posting my first message. Unfortunately it didn't work
without making the solver pre-run from excel.
Try to copy and paste these lines from
http://support.microsoft.com/default.aspx?
scid=/support/excel/content/solver/solver.asp


Sub Find_Square_Root2()

Dim val
Dim sqroot

' Request the value for which you want to get the
square root.
val = Application.InputBox( _
prompt:="Please enter the value for which you
want " & _
"to find the square root:", Type:=1)

' Set up the parameters for the model.
SolverOK SetCell:=Range("A2"), MaxMinVal:=3,
ValueOf:=val, _
ByChange:=Range("A1")

' Do not display the Solver Results dialog box.
SolverSolve UserFinish:=True

' Save the value of cell A1 (the changing cell)
before you discard
' the results.
sqroot = Range("a1")

' Finish and discard the results.
SolverFinish KeepFinal:=2

' Show the result in a message box.
MsgBox "The square root of " & val & " is " & Format
(sqroot, "0.00")

End Sub

Bye
Marco