+ Reply to Thread
Results 1 to 9 of 9

Solversolve doesn't work

  1. #1
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Solversolve doesn't work

    Hi,

    My name is Bo and I am using solver to solve my minimization problem in a loop in vba. I have set everything up and press F8 to go step by step. When I got the solversolve, it doesn't update the cell. And everytime after I ran the solversolve process, the formula calculation will be set to manual automatically and I need to change it back to automatic calculation everytime I went through solversolve. There are no errors popping up. It just doesn't have any effect on the spreadsheet. When I used the same setting and use the solver add-in by hand, it could update the cell. It just doesn't work in VBA. It will be appreciated if anyone could solve the problem. My code is :
    Sheets("Temp").Select
    Solverreset

    SolverOptions MaxTime:=0, Iterations:=0, Precision:=0.000001, Convergence:= _
    0.00001, StepThru:=False, Scaling:=True, AssumeNonNeg:=True, Derivatives:=2
    SolverOptions PopulationSize:=0, RandomSeed:=0, MutationRate:=0.075, Multistart:= _
    False, RequireBounds:=False, MaxSubproblems:=0, MaxIntegerSols:=0, IntTolerance _
    :=1, SolveWithout:=True, MaxTimeNoImp:=30
    SolverOk SetCell:="$AM$2", MaxMinVal:=2, ValueOf:=0, ByChange:="$R$17,$R$21", _
    Engine:=1, EngineDesc:="GRG nonlinear"
    SolverAdd CellRef:="$R$17", Relation:=1, FormulaText:="1"
    SolverAdd CellRef:="$R$21", Relation:=1, FormulaText:="0.5"
    SolverAdd CellRef:="$R$17", Relation:=3, FormulaText:="0.51"
    SolverAdd CellRef:="$R$21", Relation:=3, FormulaText:="0"
    solversolve userfinish:=True
    Application.ScreenUpdating = True

    Thank you!

  2. #2
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Solversolve doesn't work

    BTW, even though I could solve it by hand, I need to do it for hundreds of loops and I cannot finish this without running a code. Thanks.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: Solversolve doesn't work

    Is it possible to upload the file?

    Alf

  4. #4
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Solversolve doesn't work

    Sure, the attached file is my excel file. The work is in the sheet's name of "Temp" and the code is in Module one.I have got rid of other sheets and some code not involved in the solversolve so that it could be small enough to upload. Please let me know if you could find something wrong in it. Thanks!
    Attached Files Attached Files

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: Solversolve doesn't work

    Some good, some bad.

    The good: Changing your macro to this will make solver run

    Please Login or Register  to view this content.
    The bad. I used only command solversolv as this gives you information about the solver run and it says "Error in model" see Solver_error.pgn

    I've had a quick look at your model and I can't see how changing range R17 to R21 will make range AM2 = 0

    Alf
    Attached Images Attached Images
    Last edited by Alf; 06-06-2013 at 12:30 PM. Reason: Forgot to upload file

  6. #6
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Solversolve doesn't work

    Thank you Alf. I have used the code you used and it could run and give me the same error. Then I open solver add-in in excel and run it by hand, it could find the optimum answer and no error popping up. There is a picture of my solver setting. It will be great if you could help find the consistency between the program and the code. SolverSetting.jpg

  7. #7
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Solversolve doesn't work

    Hi,

    Thank you. I just record the macro when I used the solver add-in and use the code in the macro. It works! The code is
    Sheets("Temp").Select

    PHP Code: 
      Solverreset
        SolverOk SetCell
    :="$AM$2"MaxMinVal:=2ValueOf:=0ByChange:="$R$17,$R$21"_
            Engine
    :=1EngineDesc:="GRG Nonlinear"
        
    SolverAdd CellRef:="$R$17"Relation:=1FormulaText:="1"
        
    SolverAdd CellRef:="$R$21"Relation:=1FormulaText:="0.5"
        
    SolverAdd CellRef:="$R$17"Relation:=3FormulaText:="0.51"
        
    SolverAdd CellRef:="$R$21"Relation:=3FormulaText:="0"
        
    SolverOk SetCell:="$AM$2"MaxMinVal:=2ValueOf:=0ByChange:="$R$17,$R$21"_
            Engine
    :=1EngineDesc:="GRG Nonlinear"
        
    SolverOk SetCell:="$AM$2"MaxMinVal:=2ValueOf:=0ByChange:="$R$17,$R$21"_
            Engine
    :=1EngineDesc:="GRG Nonlinear"
        
    SolverSolve userfinish:=True
        Application
    .ScreenUpdating True 
    Thank you very much!
    Last edited by yangbo07520; 06-06-2013 at 04:20 PM.

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,792

    Re: Solversolve doesn't work

    Glad you solved it and thanks for feedback!

    When setting up a solver model for the first time I would advice against using the "SolverSolve Userfinish:=True" command as Solver will then ignore any warnings about problems with the model but just present a "solution / result" right or wrong.

    Alf

  9. #9
    Registered User
    Join Date
    04-03-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Solversolve doesn't work

    Got it. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1