vba_interested
vba_interested

Reputation: 15

Use Solver for multiple cells

As you can see, I am really new into the VBA programming. I want to execute solver 52 times for the cells AE3:AE54. The solver output should be between "0" and "1".

I created the following code to execute the solver for the cells:

Sub Solver()

Dim i As Integer

For i = 3 To 54
SolverReset
    SolverAdd CellRef:="$AE$i", Relation:=1, FormulaText:="1"
    SolverAdd CellRef:="$AE$i", Relation:=3, FormulaText:="0"
    SolverOk SetCell:="$AN$i", MaxMinVal:=2, ValueOf:="0", ByChange:="$AE$i"
SolverSolve True
Next i

End Sub

I don't have a clue to do it the right way. Can someone please help?

Upvotes: 0

Views: 6020

Answers (1)

Mark Fitzgerald
Mark Fitzgerald

Reputation: 3068

Your CellRefs are wrong. Instead of "$AE$i" it need to be "$AE$" & i.

That will evaluate to $AE$3 for your first i.

Upvotes: 1

Related Questions