+ Reply to Thread
Results 1 to 4 of 4

SOLVER Syntax Help

Hybrid View

  1. #1
    Registered User
    Join Date
    02-15-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2003
    Posts
    3

    SOLVER Syntax Help

    I'm working with the SOLVER addin in excel. I'm trying to enter a loop and an if statement in the follwoing VBA syntax:

    SolverOk SetCell:="$T$24", MaxMinVal:=2, ValueOf:="0", ByChange:=" I would like to enter here a loop and an if statement so that I can select the cells I'm interested in "
    SolverAdd CellRef:="$B$25", Relation:=2, FormulaText:="0"
    SolverSolve userFinish:=True
    Any help would be appreciated!

    Thanks,
    Augusto
    Last edited by afrausin; 02-15-2011 at 01:31 PM. Reason: Moderator request

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: SOLVER Syntax Help

    Welcome to the forum.

    I think you need to provide a little more information about what you're trying to do.

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

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-15-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: SOLVER Syntax Help

    Thanks for the welcome and sorry if I was not clear in my question!

    I am trying to dynamically select the cells in the ByChange function. I think the way to do it is to (1) define the range:

    Dim Rng as Range 
    Set Range = ...
    and (2) insert that range in the ByChange function:

    SolverOk SetCell:="$T$24", MaxMinVal:=2, ValueOf:="0", ByChange:="Rng"

    if this is the right syntax, how do I set Rng to all cells within the matrix A1:D5 that are > 0?

    Thank you!
    Augusto

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: SOLVER Syntax Help

    Maybe like this:

        Dim cell        As Range
        Dim r           As Range
    
        For Each cell In Range("A1:D5")
            If VarType(cell.Value = vbDouble) Then
                If cell.Value > 0 Then
                    If r Is Nothing Then Set r = cell
                    Set r = Union(r, cell)
                End If
            End If
        Next cell
    
        SolverReset
        SolverOk SetCell:="$T$24", _
                 MaxMinVal:=2, ValueOf:=0, _
                 ByChange:=r.Address
        ' ~

+ 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