+ Reply to Thread
Results 1 to 4 of 4

VBA Solver Loop

  1. #1
    Registered User
    Join Date
    09-15-2014
    Location
    NJ
    MS-Off Ver
    2007
    Posts
    2

    VBA Solver Loop

    Hi all,

    I'm having a problem setting up a vba solver loop. I have several columns of data, Columns A-L. I am simply trying to get all of the cells in column L set to zero by changing the values in column K. Column L has a simple formula linked to Column K and a few other cells. For my purposes I only want to adjust Column K. So K2 adjusts L2, K3 adjusts L3, etc..

    I have 326 entries so I can't do it manually.

    This is the script I wrote, but it only returns row 1, and nothing past it.

    Sub SolverMacro()
    Dim k As Long
    For k = 2 To 326
    SolverReset
    SolverOk SetCell:="$L2", _
    MaxMinVal:=3, _
    ValueOf:="0", _
    ByChange:="$K2"
    SolverSolve userFinish:=True
    Next k
    End Sub


    Can anyone find the errors in it? I'm very new at this, so please explain it as simply as possible. Thanks in advance for your help.

    Ed

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: VBA Solver Loop

    Provided the rest is fine made small adjustment:

    Please Login or Register  to view this content.
    to work on pairs Kk Lk .
    As it was written it did the K2 L2 pair 325 (326-2+1) times.

    PS. Note that code in code tags is easier to read, so please edit your post to comply with our http://www.excelforum.com/forum-rule...rum-rules.html
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    09-15-2014
    Location
    NJ
    MS-Off Ver
    2007
    Posts
    2

    Re: VBA Solver Loop

    Kaper,

    This worked perfectly, thanks a lot. I'll check out that link for the next time I post.

    Thanks again!

    Ed

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,107

    Re: VBA Solver Loop

    Your post does not comply with Rule 3 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 here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

+ 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] Using Solver in a Loop
    By mattian31 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-02-2016, 02:17 AM
  2. VBA Loop with Solver.
    By ec41tp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2011, 11:23 AM
  3. VBA Loop using solver.
    By ec41tp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2011, 05:10 AM
  4. Solver Loop
    By Boof in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2011, 01:28 PM
  5. Solver + Loop
    By k21k in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-22-2008, 10:00 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