Solver via VBA

mhenk

Well-known Member
Joined
Jun 13, 2005
Messages
591
A speadsheet I currently have has a macro that runs a goalseek. I would like to switch this so that my client can input options like the number of iterations, and the maximum amount of time.

I understand that i can do this via the solver.

My question is, is there anything that I (and the client) would need to install in VBA in order to use a macro that utilizes the solver code?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Is there anything that I can add to a workbook open event that checks to make sure that the workbook will be able to use solver via VBA?
 
Upvote 0
And I'm not seeing "SOLVER" under "References..." Where should I browse to to find this?
 
Upvote 0
If you don't see the reference to SOLVER, it must not be installed. In Excel, go to the Tools menu > Add-Ins, and look for Solver in the list. If it's there, check it and click OK. If it's not there, browse to the Excel Library directory, which by default for Excel 2003 is:

C:\Program Files\Microsoft Office\OFFICE11\Library\SOLVER

Select solver.xla and click OK or Open (I forget which), check the box for SOLVER in the Add-Ins list, and press OK again.

Once Solver is installed, it should appear in the list of references that you can check.
 
Upvote 0
Alright, i got everything working the way I want, except I'm having a hard time figuring out how some of the solver parameters. I'm using this code, and it seems to be taking MUCH more time that it should:
Code:
    SolverReset
    SolverOk Setcell:=Setcell, maxminval:=3, valueof:=equalto, bychange:=Bychanging
    solveroptions maxtime:=maxtimeip, iterations:=iterationsip, AssumeNonNeg:=True
    
    slvrres = Solversolve(True)

Is there something not clear about how the "Maximum Time" or the "Number of Iterations" works with the XL Solver Options? is time in seconds?
 
Upvote 0
MaxTime is in seconds, default 100, can be up to 32767.
Iterations default 100, can be up to 32767.

Also check your precision. If you make it too small, it will increase the calculation time.

I can't see anything that jumps right out at me as the slow factor. What happens if you use different solver options? What happens if you run the same analysis manually?
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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