×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Using Solver in VBA

Using Solver in VBA

Using Solver in VBA

(OP)
I'm trying to make a macro that will be able to me the amount of damage causes by a flood in a certain area but it doesn't work. Can't anyone find the problem?
Sub SolveurHauteur()
Dim i As Integer, s As String
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   Paramètre de base
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    debit = "$H$33"
    
For i = 43 To 47 Step 1
    s = Format(i, "0")

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   Paramètre du solveur
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   1. SetCell = Cellule cible
    '   2. MaxMinVal 1(max), 2(min), 3(égale à une valeur)
    '   3. ValueOf = La valeur (si MaxMinVal=3)
    '   4. ByChange = Cellule variable
    SolverOk SetCell:="$L$" + s, MaxMinVal:=3, ValueOf:=debit, ByChange:="$H$" + s
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   Contrainte du solveur
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   1. CellRef = Cellule ayant la contrainte
    '   2. Relation= 1(<=), 2(=), 3(>=), 4(nombre entier), 5(nombre binaire de zero ou un
    '   3. FormulaText = La valeur de la contrainte
    SolverAdd CellRef:="$H$" + s, Relation:=3, FormulaText:="0"
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '   Résoudre le solveur
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    SolverSolve userFinish:=True
    SolverReset
    Next i



End Sub

RE: Using Solver in VBA

The "Engineering Spreadsheets" forum has heaps on the Solver.  Search it.  It that fails, re-ask your question in that forum.  But do everyone (including yourself) a favour and explain in your question in what way your attempt "doesn't work".

[My first guess:  you haven't added a "reference" to the Solver in your VBA environment.]
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources