Solver Using VBA

Swoootie

Board Regular
Joined
Jun 28, 2012
Messages
66
I am producing a template Excel based optamisation tool using Solver. I want to roll this out to other members of the team but I would like there to be as little manual intervention as possible. Ideally, where there are a number of possible solutions to a problem I would like VBA to select and output a solution rather than promting the user or producing numerous pop ups.
Is there a way to do this.

Thanks
 
It's a little complicated to explain the contents of the cells but they contain numbers that when multiplied to the contents of a table aim to match the target value (the target value is the sum of 3 cells) which is calculated on the Excel spreadsheet and referenced via solver
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Andrew,

I think the problem lies in my VBA coding. I'm using "Application." as a prefix for each stage of the Solver activation process. All the solutions I have found on the internet do not have the "application.". I am unfamiliar with the syntax required for Solver. Am I doing somthing obviosuly wrong? I'm really struggling with this.

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Run "SolverAdd", "$U$46", 2, "$C$4"
Application.Run "SolverOk", "$G$86", 3, TARGET, "$B$50,$B$52"
Application.Run "SolverSolve", True
 
Upvote 0
There are some alternative avenues that I have attempted including trying to disable the "Show Trial Solution" option, but no luck so far.
 
Upvote 0
You should be able to use:

Code:
SolverAdd "$U$46", 2, "$C$4"
SolverOk "$G$86", 3, TARGET, "$B$50,$B$52"
SolverSolve True
 
Upvote 0
Hi Andrew,

Thanks for your reply.

As soon asI replace my code with the code you suggest I get a "compile error: sub or function not defined". For some strange reason the code only runs (albeit without supressing the pop-ups) when I add "application.run" as a prefix.
 
Upvote 0
Hi Andrew,

I've done that but I'm still not able to prevent the "Show Trial Solution" pop-ups from appearing.
The VBA code now reads:
SolverAdd "$U$46", 2, "$C$4"
SolverOk "$G$86", 3, TARGET, "$B$50,$B$52"
SolverSolve True

Application.DisplayAlerts = False
 
Upvote 0
Hi Andrew,

I've tried the following approaches, but none of them work to surpress the "Show Trials" popups:

SolverSolve UserFinish:=True, ShowRef:="ShowTrial"
SolverSolve UserFinish:=True
SolverSolve UserFinish:=True, ShowRef:=False

I've tried positioning these at different points of the execution code, added and removed the displayalerts option. Nothing is working and I can't find any other reference online or in textbooks of what to do in such cases.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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