Consulting

Results 1 to 3 of 3

Thread: Solver in VBA- Project Dependencies

  1. #1
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    4
    Location

    Red face Solver in VBA- Project Dependencies

    Hi Guys, i new to VBA but so far i like it and have learnt alot by viewing forums, but this has me stumped especially as i'm not good at arrays yet, i'm learning Project Management and trying to come up with my own wee Portfolio selector that i can use to find the optimum Portfolio of projects in solver,
    i can use Solver's menu to do dependencies like has to be binary wher Xj=1 (do project j) Xj=0(don't do j)
    and the dependencies Xj=1 (mandatory) , Xj >= Xi Project (j depends on project i) etc
    ok in VBA
    and Solver i have done Mandatory the easiest way i could figure out:
    i set up solver and then


    [VBA]For Each b In Range("Dependencies").Rows
    If b.Text = "Mandatory" Then
    b.Cells.Select
    b.Offset(0, -2).Select
    temp = ActiveCell.Address
    SolverAdd cellRef:=Range(temp), _
    relation:=2, _
    formulaText:="One"
    End If
    Next[/VBA]

    it works well strangely enough i know i'ts not the best, but now i'm stuck and cant figure out multiple dependencies i've tried arrays but it won't let me store cell addresses in them , my ranges the user would choose the dependency type in dropdown then the projects it relies on which is a multi-pick dropdown.
    Any ideas appreciated thanks for all the reading

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [vba]Sub test(Project As String)
    Dim arDep() As Variant
    For Each b In Range("Dependencies").Rows
    If b.Text = Project Then
    arDep(UBound(arDep)) = b.Offset(0, -2)
    ReDim Preserve arDep(UBound(arDep) + 1)
    End If
    Next b
    'I don't have Solver, so you'll have to play with this
    SolverAdd cellRef:=arDep, _
    relation:=2, _
    formulaText:="One"

    End Sub
    [/vba]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    4
    Location

    Thanks ,thats what i tried to do in my head but seemed muddled up doing it, ill test it and post back
    cheers again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •