+ Reply to Thread
Results 1 to 2 of 2

solver macro + simulation code + not updating solver values

Hybrid View

  1. #1
    Registered User
    Join Date
    07-24-2012
    Location
    England
    MS-Off Ver
    2012
    Posts
    1

    solver macro + simulation code + not updating solver values

    Dear All,
    We are writing a macro that generates some parameter distributions in one spreadsheet (Parameters), pastes them in another sheet called (Derivatives), runs the solver and then should take the optimal solution onto a third sheet called PSA.
    The problem is that the macro runs but keeps copying the same values onto PSA. Moreover, we don't see that the optimal value changes when the macro is running.
    Do you know what this is happening and how we could fix it? The macro below runs, but just doesn't update the optimal values and gives us a column with the same value in the final spreadsheet. We looked over all the threads and we can't pin down what to do with this.

    Many thanks.
    sabinemaria


    The code is:
    Sub test()
    '
    ' test Macro
    '
        Sheets("Parameters").Select
        Dim Index
        Dim Trials
        Index = 0
        Trials = 10
        
        Do
        Sheets("Parameters").Select
        Range("D1").Select
        ActiveCell.FormulaR1C1 = "1"
        Application.DisplayStatusBar = True
        
          
            Range("E7:E27").Select
            Selection.Copy
            Sheets("Derivatives").Select
            Range("C15").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
            Range("F13").Select
        
            ActiveCell.FormulaR1C1 = "10"
            Range("F14").Select
                
                SolverReset
                SolverAdd CellRef:="$F$11", Relation:=1, FormulaText:="80000"
                SolverAdd CellRef:="$F$11", Relation:=3, FormulaText:="0"
    
                SolverOk SetCell:="$B$4", MaxMinVal:=1, ValueOf:=0, ByChange:="p1_", Engine:=1 _
            , EngineDesc:="GRG Nonlinear"
                
                SolverSolve True
        
                SolverSave saveArea:=Range("$R$1")
                
            Range("$F$11").Select
            Selection.Copy
            
            Sheets("PSA").Select
            Range("B4").Select
            ActiveCell.Offset(Index, 0).Range("A1").Select
            Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=False
                
            SolverFinish KeepFinal:=2
          
            
            Sheets("Parameters").Select
            Range("D1").Select
            ActiveCell.FormulaR1C1 = "0"
            
         Index = Index + 1
               
    Loop While Index < Trials
    
    End Sub
    Last edited by Cutter; 07-24-2012 at 11:36 AM. Reason: Added code tags

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: solver macro + simulation code + not updating solver values

    @ sabinemaria

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules (Rule #3) require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. Click the Forum Rules button @ top of page to see instructions in rule #3.
    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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