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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Make sure you have your VBE reference set to Solver (Tools > References > Solver).
 
Upvote 0
Solution

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

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