+ Reply to Thread
Results 1 to 2 of 2

Solver problem - again

  1. #1
    Registered User
    Join Date
    08-17-2011
    Location
    Guelph, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    3

    Solver problem - again

    Hi, so I have a set of code that is supposed to insert a price into a cell, run solver to find the optimal amount of land to allocate to two crops, paste the results into another sheet and then run again with the next price. As the price of crop A goes up, it makes sense that the allocation to crop B would go down. This happens ok for the first few runs but then at random prices it drops way down then back up on the next price - this is not logical. It runs ok if I do it manually and run solver outside the macro. I wrote the solver part of the code by using 'Record macro' and running the solver once then copying the code into the rest of my macro.

    Any suggestions would be most helpful.

    the code is:

    Solve_Brig Macro
    '
    Sheets("Data").Select
    Dim nprice As Single
    Dim ycol As Integer

    nprice = Worksheets("Data").Cells(29, 2).Value
    ycol = 3

    Application.ScreenUpdating = False

    For y = 1 To nprice
    Sheets("Data").Select
    ActiveSheet.Cells(28, ycol).Select
    Selection.Copy
    ActiveSheet.Cells(28, 2).Select

    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False

    Sheets("Brig_OptN").Select
    Range("B8").Select
    ActiveCell.Formula = "0"
    Range("b19").Select
    ActiveCell.Formula = "0"


    SolverOk SetCell:="$B$37", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$19,$B$8"
    SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001, AssumeLinear _
    :=False, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _
    IntTolerance:=5, Scaling:=False, Convergence:=0.0001, AssumeNonNeg:=True
    SolverOk SetCell:="$B$37", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$19,$B$8"
    SolverSolve UserFinish:=True



    Sheets("Results").Select
    Range("B3:B21").Select
    Selection.Copy

    Do
    ActiveCell.Offset(0, 1).Select
    Application.ScreenUpdating = False

    Loop Until ActiveCell.Value = ""

    ActiveCell.Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    'ActiveSheet.Paste
    Application.CutCopyMode = False
    Application.ScreenUpdating = False


    ycol = ycol + 1
    Next y


    End Sub

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Solver problem - again

    Hello becg,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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