+ Reply to Thread
Results 1 to 4 of 4

Running solver several times using a for-loop

Hybrid View

  1. #1
    Registered User
    Join Date
    04-01-2015
    Location
    New London, CT
    MS-Off Ver
    Mac 2011
    Posts
    2

    Running solver several times using a for-loop

    Hello,

    I am trying to run a shortest path problem on a set of nodes. In this scenario there is one start node and three end nodes (other versions I am working on have multiple possible start nodes and many more end nodes--but I kept this one simple). I have written VBA code that should run the shortest path algorithm *using SOLVER* for each start-end pair (in this case just 3). I can step through the program and it works perfectly. When I run it all at once, however, I get a message Run-time error '1004': Method 'Calculation' of object '_Application' failed.

    Would somebody be willing to help me so that the program can run through all three iterations of Solver when I run the program, please?
    If you need a reference to the way I've set up the problem, you can visit this link: http://www.excel-easy.com/examples/s...h-problem.html

    My file (with the included VBA code--in the Sheet's code (not a module)) is included here, too.

    Response Times.xlsm

    Thank you so much!

  2. #2
    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,794

    Re: Running solver several times using a for-loop

    From you profile I see you run Mac 2011:

    There is a serious problem using Solver for Excel in Office 2011 when it is called from vba. Because Solver is a separate application, control must be transferred from Excel to Solver, and this control does not occur until after vba has terminated. This means that any processing that occurs in the vba program after the call to SolverSolve will be completed before Solver has done its task.
    So a macro for running solver will only work in a Windows environment.

    Alf

    Ps You macro loops (3 times) without error messages under Office 2010
    Last edited by Alf; 04-01-2015 at 11:32 AM. Reason: extra info

  3. #3
    Registered User
    Join Date
    04-01-2015
    Location
    New London, CT
    MS-Off Ver
    Mac 2011
    Posts
    2

    Thumbs up Re: Running solver several times using a for-loop

    Thank you, Alf! I got it to work on a Windows machine.
    (Details for anyone interested--http://www.excelforum.com/excel-programming-vba-macros/948334-excel-macro-advancing-before-solver-is-finished.html)

  4. #4
    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,794

    Re: Running solver several times using a for-loop

    You are welcome.

    By the way if you don't wont the macro to stop after each loop you could change the line

    SolverSolve
    to

    SolverSolve UserFinish:=True
    Alf

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Running Solver in a loop without popup window
    By Alf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2013, 04:17 PM
  2. VBA script for running Solver in loop
    By confusedguy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2011, 03:54 AM
  3. Running Solver a number of times
    By andrewc in forum Excel General
    Replies: 0
    Last Post: 06-03-2010, 08:32 AM
  4. running loop multiple times?
    By mister tom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2010, 01:43 PM
  5. [SOLVED] For Each Loop - running three times
    By Rick A in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2006, 01:30 PM

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