+ Reply to Thread
Results 1 to 4 of 4

Using solver with loop

  1. #1
    Registered User
    Join Date
    04-12-2013
    Location
    Somewhere
    MS-Off Ver
    Excel 2007
    Posts
    2

    Using solver with loop

    I recognize this is a common problem and I have researched the help forums but yet I cannot figure out what is knowing wrong. I am admittedly a novice when it comes to macros. I am trying to predict values for column "U" (mutiple rows) based on AI and the given constraint.

    For now, I am getting a run 1004 error on the "Do While Not..." line, but I fear more errors are coming.

    Thanks.

    Worksheets("Beirut").Activate
    Do While Not IsEmpty(Worksheets("Beirut").Range("U" & RowCount))
    RowCount = 2
    SolverReset
    SolverOk SetCell:="AI" & RowCount, MaxMinVal:=1, ValueOf:="0", ByChange:="U" & RowCount
    SolverAdd CellRef:="AJ" & RowCount, Relation:=1, FormulaText:="T" + RowCount
    SolverOk SetCell:="AI" & RowCount, MaxMinVal:=1, ValueOf:="0", ByChange:="U" & RowCount
    SolverSolve userFinish:=True
    SolverFinish keepFinal:=1
    RowCount = RowCount + 1
    Loop
    End Sub

  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: Using solver with loop

    I would try something like this
    Please Login or Register  to view this content.
    If this does not work I suggest you upload you file.

    Alf

    Ps Always wrap code when posting in this forum.
    Last edited by Alf; 04-15-2013 at 11:29 AM.

  3. #3
    Registered User
    Join Date
    04-12-2013
    Location
    Somewhere
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Using solver with loop

    Thanks much for the prompt response.

    Unfortunately the suggested fix did not work. I am still receiving a Run-time error 1004 on the row starting with "Row Count = Range..."

    I have uplodaed a file for help in clarification.Test.xlsx

  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: Using solver with loop

    Ok here is the file with the macro. As column U was empty it did not work using that column as a counter. I'm now using column T as the counter for the number of rows.

    Before you can run the macro "Run_Solver" you must set a reference to solver in VBA.

    Tab "Developer" -> "Visual Basic" -> "Tools" -> "References" and check that box "Solver" is ticked. If not you may have to browse for it. Normally found
    \Microsoft Office\Office 12\Library\Solver\Solver.xlam

    Alf
    Attached Files Attached Files

+ 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