View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
SteveM SteveM is offline
external usenet poster
 
Posts: 133
Default VBA CODE SOLVER TO RETURN VALUE

On May 26, 9:37 am, Jasper wrote:
Hello Steve,

sorry for the typo, should refer to an adjacent cell, which is a product
matrix of error-terms. The reason for using Excel in this case is to be able
to show what I've done in detail to my thesis supervisor. And the ability
that, of lined up, little changes can be easily made and tracked down in
Excel. Thanks for the heads up on analytical software nonetheless.

These 16,000 regressions will stand apart from each other so will not
interfere in any kind. It just a simple routine, as described, that needs, in
due time, 16,000 repetitions. Something I'm not eager to do manually as one
can imagine. ;)

My knowledge and skill in VBA has, by not using it for 3years, become a bit
rusty. So trying to implement your suggestion, as it is indeed what I was
looking for, I just want the solution found by the solver to be placed in
DU4, well it goes like following:

Sub test()
SolverReset
SolverOk SetCell:="$DV$4, MaxMinVal:=2, ValueOf:=1", ByChange:="$DU$4"
Dim retVal As Integer 'I believe one first has to specify something to be
integer followed by the direction on what the value of the integer is, in
this case solversolve
retVal = SolverSolve(UserFinish:=True) 'as I don't have a need to see the
dialog
MsgBox retVal
SolverFinish KeepFinal:=1
End Sub

Alas, I get the "Types do not match" I'm gonna try to find out why, though
as anybody has got any suggestion as to why, I'm open to that. Thank you so
far!

Jasper


Jasper,

Now you really have me confused as to what your intent is.

First, retVal is not the solution value of the model, it is the solver
status value. I.e., what kind of solution was delivered. E.g.,
feasible, infeasible, unbounded, etc. Frontline now hides their
documentation link and makes it available only to licensed users. But
that contains the return codes for solver. You may be able to do a
web search and track them down someplace else.

So back to your model itself. It still doesn't make sense. The the
model solution value is your SetCell. So you have that defined. The
ByChange value is supposed to be the range of decision variables. If
you are only defining a single cell as a single decision variable,
there's not much of a problem. Especially because you are not
defining any constraint sets.

Which leads me to ask about your 16,000 repetitions. Are you actually
looking to do a simulation with 16,000 repetitions? Because if you
are, you are using the wrong platform. Solver is an optimization
engine not a simulation engine.

If you do indeed have a simulation problem, and the model is pretty
simple, you could code up a 16,000 iteration model in VBA using
Excel's built-in Random function. Or to make your life easier, you
could download a trial version of a simulation software package
like@Risk or Crystal Ball and just try to get all your model runs in
before the trial period runs out. Although I would guess that your
university has copies of spreadsheet simulation software available for
student use.

SteveM