+ Reply to Thread
Results 1 to 9 of 9

Macro Loop for Solver

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Macro Loop for Solver

    Hi,

    I am very new to macro and am trying to create a loop for solver, but I can't seem to get it right

    basically I have 2 separate sets of solver

    1st: minimize col L by changing col M to S & also make sure sum of col M to S = 1

    each set of solver only pertains to 1 row e.g. minimize cell L2 by changing M2:S2 & Sum(M2:S2)=1

    2nd: minimize col V by changing col W to AC

    each set of solver only pertains to 1 row e.g. minimize cell V2 by changing W2:AC2

    I would appreciate the help given by anyone thanks
    Attached Files Attached Files
    Last edited by kchm_2000; 12-27-2010 at 12:16 PM. Reason: wrong forum

  2. #2
    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: Macro Loop for Solver

    Welcome to the forum.

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

  3. #3
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Macro Loop for Solver

    thanks for your help, is there a possibility of changing it so that there is no need for a command button, sorry for the trouble and the duplicate post.

  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: Macro Loop for Solver

    You can remove the Private part and change the name of the sub to anything you like, then run it from the macro dialog (Alt+F8).

  5. #5
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Macro Loop for Solver

    i tried adding another module but but it gives me

    compile error:

    sub or function no defined


    on the solver reset line

    the error file is attached to this comment
    Attached Images Attached Images
    Last edited by kchm_2000; 12-27-2010 at 01:28 PM.

  6. #6
    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: Macro Loop for Solver

    You need to set a reference to Solver in Visual Basic:

    To reference the Microsoft Excel Solver add-in for macros in your workbook, use the following steps:
    Open your workbook.
    On the Tools menu, point to Macro, and then click Visual Basic Editor.
    On the Tools menu, click References.
    In the Available References list, click to select the Solver.xls check box, and then click OK.

    Note If you do not see Solver.xls in the Available References list, click Browse. In the Add Reference dialog box, locate and select the Solver.xla file, and then click Open. The Solver.xla file is typically found in the C:\Program Files\Microsoft Office\Office\Library\Solver subfolder.
    You are now ready to use the Microsoft Excel Solver functions in a VBA macro.

  7. #7
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Macro Loop for Solver

    Great it works, you can't believe how grateful I am. But I need to add one more constrain to my solver can you please help me add for both

    1st: minimize col L by changing col M to S & also make sure sum of col M to S = 1

    each set of solver only pertains to 1 row e.g. minimize cell L2 by changing M2:S2 & Sum(M2:S2)=1

    AND ALSO make sure that cells M2:S2 are all positive

    2nd: minimize col V by changing col W to AC

    each set of solver only pertains to 1 row e.g. minimize cell V2 by changing W2:AC2

    AND ALSO make sure that cells W2:AC2 are all positive

    I would like to know also how to adjust the macro if I have to add more variables i.e. incease number of asset factors

    thanks a lot

  8. #8
    Registered User
    Join Date
    12-28-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Macro Loop for Solver

    Hi,
    I just want to know that if I have a data in a excel sheet (Heading like BRANCH NAME & PRODUCT NAME) branch name like Agra, Delhi, Noida, Patna, Pune etc. I just want to write a macro in excel that when I run the macro automatically make a branch wise separate sheet like Agra’s related data in a separate sheet Delhi’s related separate sheet etc.
    Please help ([email protected])

  9. #9
    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: Macro Loop for Solver

    Hi aftab.vg

    Don't break forum rules.

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.
    kchm_2000

    Your request is way over my present macro/solver know how so hopefully shg will fix your problems.

    Alf

+ 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