+ Reply to Thread
Results 1 to 9 of 9

Solver is not changing values in target cell using through VBA

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Solver is not changing values in target cell using through VBA

    Hello to all VBA Wizards!!!

    I am struggling with a problem and it is giving me very hard time.

    I am using Solver function in a worksheet using VBA.

    Initially Solver was being used manually in the Template, however now I want to automate this. I used recorded macro to Maximize and Minimize the Correlation function output.

    It worked 3-4 time initially but stopped working at once after it and I have tried everything by deleting/setting the ranges manually but no results.

    I Googled it and used Solver.Solver2.Auto_Open but nothing happened.

    The VBA code runs, not giving any error but the values are not changing in Target Cell.

    Kindly provide the solution if there is any as this task has to be completed by tomorrow max.

    Appreciate you help!!

    Regards,
    Brajpal Shishodia

  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: Solver is not changing values in target cell using through VBA

    Post your code?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Solver is not changing values in target cell using through VBA

    Thanks for the reply.

    Please find the codes below


    Sub Max_solver()

    ' Set up the parameters for the model.
    ' Determine the maximum value for correlation value in cell O12
    ' by changing the number of units to build in cells w15:W22.

    ' Clear any previous Solver settings.
    SolverReset

    SOLVER.Solver2.Auto_open

    'for maximization maxminval =1
    'for minmization maxminval = 2
    'for meeting speacial value of 75 maxminval =3 and valueof = 75
    SolverOk SetCell:=Range("$n$12"), MaxMinVal:=1, _
    ByChange:=Range("$w15:$w$41")


    'LESS THAN CONSTRAINT
    SolverAdd CellRef:=Range("$C$10"), Relation:=1, _
    FormulaText:="0.8"

    'MORE THAN CONSTRAINT
    SolverAdd CellRef:=Range("$C$10"), Relation:=3, _
    FormulaText:="0.001"

    ' Add the constraint for the model. The only constraint is that the
    ' number of parts used does not exceed the parts on hand--
    ' $w$15:$w$22 <= $x15:$x$22 and $w$15:$w$22 >= $v15:$v$22
    'LESS THAN CONSTRAINT
    SolverAdd CellRef:=Range("$w15:$w$41"), Relation:=1, _
    FormulaText:="$x$15:$x$41"

    'MORE THAN CONSTRAINT
    SolverAdd CellRef:=Range("$w15:$w$41"), Relation:=3, _
    FormulaText:="$v$15:$v$41"

    SolverOk SetCell:="$N$12", MaxMinVal:=1, ValueOf:="0", ByChange:="$W$15:$W$41"

    ' Do not display the Solver Results dialog box.
    SolverSolve UserFinish:=True

    ' Finish and keep the final results.
    SolverFinish KeepFinal:=1

    End Sub

    Sub Min_solver()

    ' Set up the parameters for the model.
    ' Determine the maximum value for correlation value in cell O12
    ' by changing the number of units to build in cells w15:W22.

    ' Clear any previous Solver settings.
    SolverReset

    SOLVER.Solver2.Auto_open

    SolverOk SetCell:=Range("$n$12"), MaxMinVal:=2, _
    ByChange:=Range("$w15:$w$41")


    'LESS THAN CONSTRAINT
    SolverAdd CellRef:=Range("$C$10"), Relation:=1, _
    FormulaText:="0.8"

    'MORE THAN CONSTRAINT
    SolverAdd CellRef:=Range("$C$10"), Relation:=3, _
    FormulaText:="0.001"


    ' Add the constraint for the model. The only constraint is that the
    ' number of parts used does not exceed the parts on hand--
    ' $w$15:$w$22 <= $x15:$x$22 and $w$15:$w$22 >= $v15:$v$22
    SolverAdd CellRef:=Range("$w15:$w$41"), Relation:=1, _
    FormulaText:="$x$15:$x$41"

    SolverAdd CellRef:=Range("$w15:$w$41"), Relation:=3, _
    FormulaText:="$v$15:$v$41"


    SolverOk SetCell:="$N$12", MaxMinVal:=2, ValueOf:="0", ByChange:="$W$15:$W$41"

    ' Do not display the Solver Results dialog box.
    SolverSolve UserFinish:=True

    ' Finish and keep the final results.
    SolverFinish KeepFinal:=1

    End Sub


    Sub Solver_Test()

    'SolverOk SetCell:="$N$12", MaxMinVal:=2, ValueOf:="0", ByChange:="$W$15:$W$41"
    SolverAdd CellRef:="$C$10", Relation:=1, FormulaText:="0.8"
    SolverAdd CellRef:="$C$10", Relation:=3, FormulaText:="0.001"
    SolverAdd CellRef:="$W$15:$W$41", Relation:=1, FormulaText:="$X$15:$X$41"
    SolverAdd CellRef:="$W$15:$W$41", Relation:=3, FormulaText:="$V$15:$V$41"
    SolverOk SetCell:="$N$12", MaxMinVal:=1, ValueOf:="0", ByChange:="$W$15:$W$41"
    SolverSolve True
    'SolverOk SetCell:="$N$12", MaxMinVal:=2, ValueOf:="0", ByChange:="$W$15:$W$41"
    'SolverSolve

    End Sub

  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: Solver is not changing values in target cell using through VBA

    Which of those routines is relevant?

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

  5. #5
    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: Solver is not changing values in target cell using through VBA

    Your code doesn't follow the narrative:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Solver is not changing values in target cell using through VBA

    Hi Shg,

    Appreciate your help on this.

    Yes, actually I modified the existing code that is why it is reflecting like that.

    The problem is in cells "W15:W41".

    These cells should change accordingly when I run the code for Maximize/Minimize.

    For Maximize the values on W15:W41 should change with X15:X41 and for Minimize W15:W41 values should change with V15:V41, but this is not happening.

    it is the cause of problem.

    Thanks
    Brajpal Shishodia

  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: Solver is not changing values in target cell using through VBA

    Post the workbook.

  8. #8
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Solver is not changing values in target cell using through VBA

    Hello shg,

    I spent a lot of time on it and then finally I found the solution of my problem.

    The cell reference issue was there. I tracked it and now the Solver is working fine now.

    I really appreciate the prompt response you gave on this post.

    Best Regards,
    Brapal Shishodia

  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: Solver is not changing values in target cell using through VBA

    You're welcome.

+ 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. Solver changing cell based on a list
    By KBecker in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-22-2014, 11:46 AM
  2. Changing Formula based on what is in the target cell
    By 5upgraphics in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-02-2014, 05:54 PM
  3. Solver - Changing cells to text values not integer
    By Kinnan in forum Excel General
    Replies: 0
    Last Post: 08-15-2010, 08:46 AM
  4. Solver constraints shall be OR // Solver target cell
    By Cunner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2009, 04:28 AM
  5. changing color of values bigger or smaller than target
    By Fedde in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 03-27-2006, 08:28 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