+ Reply to Thread
Results 1 to 7 of 7

VBA to loop solver

  1. #1
    Registered User
    Join Date
    10-19-2018
    Location
    Sydney, Australia
    MS-Off Ver
    multiple - mostly excel 2016 32-bit
    Posts
    3

    Unhappy VBA to loop solver

    Hi.
    I am new to using VBA, apologies if this is very basic.... but I've been unsuccessful in implementing tips from other posts.

    I have a column of 101 values on 4 sheets that I need to use SOLVER to calculate.

    The formula is located in column F, the ouput I am solving for located in column E, and I am solving for 0.

    When I record a macro, it looks like this
    Please Login or Register  to view this content.

    My question is, how do I create a loop/automate this so that after it finds a solution for row 52, it jumps to row 53 and does the same thing, all the way to row 151?

    I have attached my full spreadsheet. The sheet I am using as an example is "Wheat HL"

    I am using MS excel 2016, 32 bit.

    I really appreciate any help!! I've had to manually run this several times already as other parameters in my model change
    Attached Files Attached Files
    Last edited by alansidman; 10-19-2018 at 04:09 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: VBA to loop solver

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: VBA to loop solver

    We have several examples of running Solver within loops here. A couple I keep handy:
    Here's a fairly simple example of a loop: https://www.excelforum.com/excel-pro...ml#post4887763
    Another: https://www.excelforum.com/excel-pro...ml#post4546973

    Are you already familiar with VBA's (similar to other programming languages) loop structures? https://www.dummies.com/software/mic...xcel-2016-vba/
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: VBA to loop solver

    What you wish to do is to run solver in a loop. Before running solver using VB you must set a reference to Solver.

    Developers tab click Visual Basic icon.In new Window that opens click Tools -> References and than tick box marked "Solver"

    The loop code could look like this:

    Please Login or Register  to view this content.
    The "SolverReset" command clears the previous settings E52, E53, E54 ....... and the line "SolverSolve UserFinish:=True" will ignore the usual vstop command so that solver loops through all values of i before it stops.

    Alf

  5. #5
    Registered User
    Join Date
    10-19-2018
    Location
    Sydney, Australia
    MS-Off Ver
    multiple - mostly excel 2016 32-bit
    Posts
    3

    Re: VBA to loop solver

    thanks! will do next time.

  6. #6
    Registered User
    Join Date
    10-19-2018
    Location
    Sydney, Australia
    MS-Off Ver
    multiple - mostly excel 2016 32-bit
    Posts
    3

    Re: VBA to loop solver

    this worked perfectly, thank you!

  7. #7
    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: VBA to loop solver

    You are welcome and thanks for feedback.

    As this seems to solve you problem don't forget to mark you thread "Solved" as per forum rules.

    Alf

    To mark your thread solved do the following:

    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

+ 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] Loop Solver using VBA
    By T15K in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2015, 06:38 AM
  2. Solver VBA Loop
    By excelnoobie164 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-13-2014, 12:15 PM
  3. [SOLVED] Solver For Loop
    By Hayashi151 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-16-2014, 05:32 PM
  4. Using Solver in a VBA loop
    By blitz13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2013, 01:24 PM
  5. Using solver with loop
    By mat1973 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2013, 02:01 PM
  6. VBA Loop with Solver.
    By ec41tp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2011, 11:23 AM
  7. VBA Loop using solver.
    By ec41tp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2011, 05:10 AM

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