Assign Solver to a Command Button in VBA

shuxin

New Member
Joined
Sep 19, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hello, I'm trying to assign the solver function to a command button in VBA but it says there is an error. My solver code is like this (I used record macro)
Sub solver()
SolverOk SetCell:="$B$35", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$25:$H$31", _
Engine:=2, EngineDesc:="Simplex LP"
SolverOk SetCell:="$B$35", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$25:$H$31", _
Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
End Sub

and i pasted it under my command button but it says error. how can i change this?
Private Sub cmbassign_Click()

SolverOk SetCell:="$B$35", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$25:$H$31", _
Engine:=2, EngineDesc:="Simplex LP"
SolverOk SetCell:="$B$35", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$25:$H$31", _
Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

rlv01

Well-known Member
Joined
May 16, 2017
Messages
1,982
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Make sure you have your VBE reference set to Solver (Tools > References > Solver).
 
Solution

Forum statistics

Threads
1,181,999
Messages
5,933,179
Members
436,883
Latest member
RyanI1986

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