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?
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Hydraulics

New Member
Joined
Nov 27, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
You have to add a reference. From the VBE menu, go to Tools -> References, then check the box in front of Solver.

HTH,

Francesco
 

Watch MrExcel Video

Forum statistics

Threads
1,127,613
Messages
5,625,848
Members
416,139
Latest member
MattBoard

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
Top