Hi

I am fairly new to VBA and have just encountered a problem when dealing with the Solver Add-in.

I'd like to run the below code without having to select the sheet "IRR".
Unfortunately, it only works when "IRR" is selected (otherwise the solver results are posted in Cell B40 on the active sheet). How can I change the code so that it fits my needs?


Sub GetIRR()

Dim dcf as Long
dcf = Sheets("IRR").Range("B24").Value

    SolverReset
    SolverOk SetCell:=Sheets("IRR").Range("$B$40"), MaxMinVal:=3, ValueOf:=dcf, ByChange:=Sheets("IRR").Range("$B$42")
    SolverSolve True

End Sub

Thanks a lot for your help!