+ Reply to Thread
Results 1 to 12 of 12

Excel 2010 Looping solver macro

  1. #1
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Excel 2010 Looping solver macro

    Hello,

    I'm relatively new to VB, and to the forum, I'd appreciate your help with the following.

    I'm trying to use solver to optimise a value in cell O5 so that it's identical to a value in cell P5 by changing cells E5 & F5. I'm also trying to loop the code so that the sequence is repeated for every subsequent row until row 781.

    I've so far tried using the following code, but to no avail:

    Please Login or Register  to view this content.
    Can anyone point out where I'm going wrong, or give me any pointers please?
    Last edited by RG84; 09-16-2013 at 12:13 PM.

  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,758

    Re: Excel 2010 Looping solver macro

    At the moment you are running solver with fixed values. I can't see you are using r to update any solver parameter. Could this be what you wish to do?

    Please Login or Register  to view this content.
    Looping solver using VBA will not work om the MAC version of solver.

    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.

    Thus a vba program to call solver and then capture or process the results _cannot_ work. It also precludes calling Solver from vba in a loop even though the documentation suggests this is possible
    Alf
    Last edited by Alf; 09-16-2013 at 02:09 PM.

  3. #3
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Re: Excel 2010 Looping solver macro

    Hi Alf, thanks for your reply.

    It might just be my lack of experience with VBA, but I had assumed that r referred to the row? If not, then I've gone wrong somewhere.

    Unfortunately your code returns a compile/syntax error, again probably because of my poor code in the first place.

    RG

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel 2010 Looping solver macro

    Maybe ...

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  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,758

    Re: Excel 2010 Looping solver macro

    but I had assumed that r referred to the row?
    Yes it can do but as your original expression is fixed i.e.
    Please Login or Register  to view this content.
    the value will never change but if the expression is
    Please Login or Register  to view this content.
    then the r value will change for each "Next" and expression goes from O2 to O781.

    Could you perhaps upload a file with your model then it's easier to trouble shoot.

    Alf

  6. #6
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Re: Excel 2010 Looping solver macro

    Hi shg, thanks for your reply.

    That works perfectly, but only as far as row 75. After that, the remaining cells come up with a #DIV/0! error.

    The solved E75 cell has been changed to 0. That's fine, but is there some way that this is stopping the remaining cells from solving?

    Thanks!
    Last edited by RG84; 09-16-2013 at 03:48 PM.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel 2010 Looping solver macro

    What happens at row 75?

    I second Alf's suggestion.

  8. #8
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Re: Excel 2010 Looping solver macro

    I've uploaded the file to Dropbox, which can be accessed here: https://dl.dropboxusercontent.com/u/...Model2010.xlsm . The active worksheet is sheet 2.

    I'm not sure what happens other than nothing is solved past that point. The macro seems to complete and returns no errors, but row 75 is the cutoff.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel 2010 Looping solver macro

    Looks to me like col E needs to be constrained to be >0.

  10. #10
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Re: Excel 2010 Looping solver macro

    That makes sense, how can I write that into the macro?

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel 2010 Looping solver macro

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-16-2013
    Location
    Norfolk, UK
    MS-Off Ver
    Office 2010 Windows / Office 2011 Mac
    Posts
    6

    Re: Excel 2010 Looping solver macro

    That works perfectly, thank you very much for your help shg & 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] Find All function looping in Excel 2010
    By XML2005 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-12-2013, 12:02 AM
  2. Solver don't work in excel 2010
    By masben in forum Excel General
    Replies: 5
    Last Post: 02-27-2013, 11:20 AM
  3. [SOLVED] Looping Through Sheets in a workbook in Excel 2010
    By Johnr1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2012, 05:09 AM
  4. Solver macro (2010) does not work in 2007
    By goldenaggregate in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2012, 09:59 AM
  5. Using Solver from VBA Excel 2010
    By secret2 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-05-2012, 07:12 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