Need help with vba solve function RRS feed

  • Question

  • I am new in writing Codes in VBA. I have to solve a complicating equation using vba. I am allowed to use the solve function. So to learn I am first trying to solve this simple equation : 
    a = 2
    b = 3
    c = Cells(2, 1)
    c = a * t + b * t ^ 0.2

    Say, I need to solve for t. Can you help me with a simple code to solve for t using the solver functions?

    Thanks in advance!
    Saturday, December 6, 2014 6:47 PM

All replies

  • With 2 in A1, 3 in A2, and any value for t in cell A3, in another cell -say, A4 - use the formula


    and the desired value in cell B

    Then use solver like this in a macro

    Sub Macro1()
        SolverOk SetCell:="$A$4", MaxMinVal:=3, ValueOf:=Cells(1, 2).Value, ByChange:="$A$3", Engine:= _
            1, EngineDesc:="GRG Nonlinear"
        SolverFinish KeepFinal:=True

    End Sub

    You will need to set a reference to Solver in your project, and have the add-in installed in your Excel settings.

    Thursday, December 11, 2014 8:44 PM