Solver Operating on VBA values?

Phod

New Member
Joined
Mar 29, 2010
Messages
9
Solver can be used for example to fit a model like a line (y=mx+b) to a data set (X,Y) using solver to minimize the sum of the square of the difference between the model Y's and the data Y's by changing the slope and intercept, m and b. Here the model calculations are made on a sheet using Ymodel = m*X+b at every X.

But what if VBA was used to generated the model data? Can solver still be exploited for its utility?

Reason:

I have VBA code that generates model data but its too complicated to easily do in a spreadsheet so I run the macro to generate and output these numbers. That is, if I changed a parameter sort of equivalent to the "m" and "b" above, I must run the VBA code to generate new Ymodel values.

I'm curious if solver can be used in a macro when the relationship between "the values its changing" and the value its "minimizing, maximizing, or driving to value" has to be updated thru a VBA routine since they are not linked in a direct way through expressions on a sheet?

Hope the inquiry is clear enough. Thanks.


-- removed inline image ---
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You need to put the data on a worksheet and automate Solver in the usual way.
 
Upvote 0
You need to put the data on a worksheet and automate Solver in the usual way.


I think you are suggesting to re-code the equations that are currently in the VBA code into a spreadsheet... That would work in theory. But in my case it isn't possible because the VBA code is quite complicated and includes a step-wise Eulerian integration that cannot be readily translated to equations in a worksheet.

Any other suggestions?
 
Upvote 0
The SetCell and the changing cells need to be on the worksheet; that's how Solver works.

You can have UDFs (but not Subs) in the SetCell calculation chain.
 
Last edited:
Upvote 0
Ah ha! A User-Defined Function... That might just work...

I'll give it a try and report back. Thanks for the idea!
 
Upvote 0
You're welcome.

Make sure that all relevant arguments are passed to the UDF, so that Excel sees all dependencies.

Good luck.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top