How to automate simple solver?

Garrek

Board Regular
Joined
Aug 22, 2019
Messages
53
Have been trying to automatically run a solver i have set up through a macro, but after using the recorder to create the macro I am getting a "Sub or function not defined" error, with "SolverOK highlighted.

VBA Code:
Sub OptimizeDedicated()
'
' OptimizeDedicated Macro
'

'
Worksheets("Dedicated Model").Activate

    SolverAdd SetCell:="$O$2", MaxMinVal:=2, ValueOf:=0, ByChange:="$A$2:$A$201", _
        Engine:=3, EngineDesc:="Evolutionary"
    SolverOk SetCell:="$O$2", MaxMinVal:=2, ValueOf:=0, ByChange:="$A$2:$A$201", _
        Engine:=3, EngineDesc:="Evolutionary"
    SolverSolve
End Sub

There is my code, I am trying to minimize cell O2 on Sheet "Dedicated Model", by changing A2:A201, with the constraint that A2:A201 are all different (isdif). Using an evolutionary model. Any insight on why this isnt working?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You have to add a reference. From the VBE menu, go to Tools -> References, then check the box in front of Solver.

HTH,

Francesco
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,158
Members
449,208
Latest member
emmac

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