locked
VBA Solver RRS feed

  • Question

  • Hi,

    I'm having issues writing code in VBA for the Solver function. I believe the problem lies within the function's ability to read formats or, rather, me not writing in a format that the SolverOk and SolverAdd can understand.

    The solver is to be used in a loop, and thus the cells called will change.

    Any help would be greatly appreciated. The code is here below.

    Thanks,

    Bruno

    +++++++++++++++++++++++++++

    For line = 12 to 13

    SolverOk SetCell:="AM" & line, _                             ' for each of the for loop's step, the row of the cell changes    maxMinVal:=1, _
        ByChange:=Range("av" & line, "bc" & line), _         ' I want it to vary two cells, which are not next to each other
        Engine:=3                                                       ' could be other

    SolverAdd cellref:="AV" & line, _                             ' for each of the for loop's step, the row of the cell changes   
        relation:=1, _
        formulaText:=cells(9,52)                                    'Fixed. Its the upper bound
       
    SolverAdd cellref:="AV" & line, _
        relation:=3, _
        formulaText:="0"                                              'Fixed. Its the lower bound

    SolverAdd cellref:="bc" & line, _                              'for each of the for loop's step, the row of the cell changes   
        relation:=1, _
        formulaText:=cells(9,52)                                    'Fixed. Its the upper bound
       
    SolverAdd cellref:="bc" & line, _
        relation:=3, _
        formulaText:="0"                                              'Fixed. Its the lower bound

    Next

    Friday, July 25, 2014 7:29 PM