Macro works in Personal.xlsb but not in file.xlsm??

Kenn

Board Regular
Joined
Sep 23, 2009
Messages
195
This one 's got me stumped! I created this macro in the personal.xlsb & it worked perfectly. Then copied it to a module in the xlsm file & deleted the original. Now getting I am getting a "Compile error: Sub or function not defined"
Anyone got any idea what I'm doing wrong here? Thank you. Kenn.

Code:
Sub Optimise()
Dim X As Integer

Application.ScreenUpdating = False

On Error Resume Next
        
    For X = 1 To 20
        Range("B2").Value = X
        Range("B3").Value = ""
        [COLOR=#ff0000]SolverReset [/COLOR]     [COLOR=#ff0000] ' Here I am getting a "Compile error: Sub or function not defined"[/COLOR]
        SolverOk SetCell:="$B$9", MaxMinVal:=3, ValueOf:=1, ByChange:="$B$3", Engine:=1, EngineDesc:="GRG Nonlinear"

        SolverAdd CellRef:="$B$3", Relation:=1, FormulaText:="$B$2"
        SolverAdd CellRef:="$B$3", Relation:=3, FormulaText:="0"
        SolverAdd CellRef:="$B$9", Relation:=1, FormulaText:="1.02"
        SolverAdd CellRef:="$B$9", Relation:=3, FormulaText:="0.98"

        SolverOptions MaxTime:=60, Iterations:=10, Precision:=0.01, Convergence:=0.01, _
            StepThru:=False, Scaling:=False, AssumeNonNeg:=False, Derivatives:=2
        SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
            :=False, RequireBounds:=False, MaxSubproblems:=0, MaxIntegerSols:=0, _
            IntTolerance:=2, SolveWithout:=False, MaxTimeNoImp:=30

        SolverSolve UserFinish:=True
        Application.Calculation = xlCalculationAutomatic
        
        If Range("B9").Value >= 0.98 And Range("B9").Value <= 1.02 Then
            Range("H2").Select
            Cells.Find(What:=X, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
            Selection.PasteSpecial Paste:=xlPasteValues
            ActiveCell.Offset(0, 1) = Range("B3").Value
            ActiveCell.Offset(0, 2) = Range("B9").Value
        Else
        End If
    Next X
        Range("B2").Value = Range("K2").Value
        Range("B3").Value = Range("L2").Value
        Range("I2:J21").Value = ""
    
Application.ScreenUpdating = True
End Sub
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Kenn

Board Regular
Joined
Sep 23, 2009
Messages
195
Nevermind. I figured it out. VBA Tools >> References >> Tick Solver >> OK.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,668
Messages
5,597,463
Members
414,145
Latest member
lonnie451

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