View Single Post
  #5   Report Post  
MrShorty
 
Posts: n/a
Default


I was of the impression you were using a Function procedure, not a Sub
procedure.

I've never been good at invoking Solver from within VBA; I gave up on
that approach rather quickly in what I was doing. The key, I think, in
your case, is to get what's going to be the target cell to contain a
formula rather than just a value. Here's an idea:

Public FUNCTION GetResults(size as double) as variant
Dim results as ResultsObject
results=ComplexCalculation(size)
Dim temp(2,1) as double
temp(1,1)=results.Mass
temp(2,1)=results.Temperature
GetResults=temp
End Function

Put size in B1
Select B2:B3 and array enter =GetResults(B1)

Then write the calculate subroutine that will invoke Solver. Like I
said, I'm not real good with that. The easiest way would probably be
to record a macro while you run Solver manually (targetcell=B3 to
Maximum by changing B1 with the constraint that B2 <= constraint on
mass). Then put the recorded code into a worksheet_calculate procedure
and adapt it to do exactly what you need.

As with most programming, there are going to be other possible
solutions. If you don't feel able to write your own optimization code,
then this should be one way to get what you want.


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=390924