Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Solver in VBA

Status
Not open for further replies.

Tallmarc

Civil/Environmental
Joined
Feb 25, 2009
Messages
1
Location
CA
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
 
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.]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top