The following line of code is giving me Sub or Function not defined whenever I try to use it. I've tried double checking my spelling, renaming it, looking up other questions online (most other mistakes were forgetting to add an s after sheets or worksheets), but I have no idea what's wrong with my code. I originally got this code from the macro recorder.
I am using this sub multiple times on different sheets, but that hasn't affected my other subs that are similar.
Sub SolverSolver()
SolverOk SetCell:="$G$3", MaxMinVal:=2, ValueOf:=0, ByChange:="$G$4,$G$6", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
End Sub
Maybe the way in which it's being used is what's wrong, so I've added the way in which its called below. This line is in a large sub of simple commands like giving a cell a name, and this large simple sub also repeats multiple times. However even when attempting to run the sub by directly running it though the developer tab, it still has the same error so I don't think its the way the sub is called.
ActiveSheet.Buttons.Add(630.75, 52.5, 74.25, 26.25).OnAction = "SolverSolver"
Any help would be greatly appreciated!
You dont have reference set to Solver. To use Solver functions that'
s manadatory. Set it like this: in VBA editor, Go to Tools --> References --> and select Solver. Click OK.

Also make sure that you have enabled the Solver Add-In, In Excel you can enable it by File--> Options --> Add-ins , here selecet Excel Add-Ins under manage dropdown and click go. On The next screen check Sover Add-In and click OK.
As GSerg mentioned, if your SolverSolver sub is in a sheet module , then you need to include the module name in action param value. So if sheet1 contains the sub then
ActiveSheet.Buttons.Add(630.75, 52.5, 74.25, 26.25).OnAction = "Sheet1.SolverSolver"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With