I am trying to create a function which uses the Solver but I am getting a runtime error 438 method range of object worksheet failed. Please see code below:
Function DepreciationProfilingMethod(WS As Worksheet, Var As Range, Adj As Range)
SolverReset
SolverOptions Assumenonneg:=False
SolverOK SetCell:=WS.Range("Var"), MaxMinVal:=3, ValueOf:=0, ByChange:=WS.Range("Adj"), EngineDesc:="GRG Nonlinear"
SolverSolve (True)
End Function
Sub RunDepreciationMacro()
Dim C_TRS As Excel.Worksheet
Dim WorkB As Workbook
Set C_TRS = ThisWorkbook.Sheets("C_TRS")
Set WorkB = ThisWorkbook
Call addsolver
'Error in this line
Call DepreciationProfilingMethod(C_TRS, C_TRS.Range("Var_2023"), C_TRS.Range("Adj_2023"))
End Sub
I have tried to add a worksheet as a parameter to the function but this has not resolved the error and not sure how to resolve this.
SolverOK SetCell:=Var, MaxMinVal:=3, ValueOf:=0, ByChange:=Adj, EngineDesc:="GRG Nonlinear".AdjandVarareRangeobject argument. You can't use it asWS.Range("Var")."Var"assuming that's the address you're passing. If it's a named range LITERALLY being "VAR" than there's no need for the parameter. Also, be more specific where the error is. A``type` error is just the wrong type of object (so like instead of a number it's getting a range) and should be easy to fix.