View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Marco[_7_] Marco[_7_] is offline
external usenet poster
 
Posts: 1
Default Problems with solver and vba

Dear all,
i'm trying to create a Visual Basic Macro that uses Excel
Solver.
I simply put on cell A1 a numeric value (example 3) and
on cell B1 the formula =A1*A1
Then in VBA i write the following:

-----------------------------------------------------
Sub Find_Square_Root()

' Set up the parameters for the model.
' Set the target cell A2 to a Value of 50 by changing
cell A1.
SolverOK SetCell:=Range("A2"), MaxMinVal:=3,
ValueOf:=50, _
ByChange:=Range("A1")

' Solve the model but do not display the Solver
Results dialog box.
SolverSolve UserFinish:=True

' Finish and keep the final results.
SolverFinish KeepFinal:=1

End Sub
----------------------------------------------------------

Unfortunately by executing the macro from EXCEL nothing
happens. It seems that SOLVER is not able to load the
variables.
I can solve the problem by making a pre-run of SOLVER
from EXCEL setting the target cells and the cells to be
modified by hand.
Once that this pre-run is done I can load the macro that
works perfectly.

Is there any way to avoid initialising SOLVER from EXCEL
by hand and let it work from the macro?

thanks
Marco