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.
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