Michela Benazzi
Michela Benazzi

Reputation: 11

Looping Excel Solver macro by row

I am aware this is a very common question but I still don't understand what to do after spending hours on examples.

I have about 3600 rows of thermodynamic data for two columns (T and V). I am trying to loop Solver to zero T7:T3624 by changing V7:V3624. Each T only depends on its respective V.

Sub CHE561Project2()
CHE561Project2 Macro

SolverReset
Dim count As Integer
Set count = 1
Do While count <= 3617
SolverOk SetCell:=Sheets("Mixing").Cells("$T$", count), MaxMinVal:=3, ValueOf:=0,
ByChange:=Sheets("Mixing").Cells("$V$", count).Value, EngineDesc:="GRG Nonlinear"
SolverSolve userfinish:=True
Sheets("Mixing").Cells(count, ).Value = Sheets("Mixing").Cells(count, ).Value
count = count + 1
Loop
End Sub

I am not quite sure what I am doing, to be honest. I would appreciate any help!

Upvotes: 0

Views: 507

Answers (1)

Michela Benazzi
Michela Benazzi

Reputation: 11

UPDATE: I just changed it to this and it worked!! :)

Sub CHE561Project2()
    'CHE561Project2 Macro
    Dim startingRow As Long
    Dim endingrow   As Long
    Dim i           As Long
    startingRow = 7
    endingrow = 3624
    For i = startingRow To endingrow
    SolverReset

    SolverOk SetCell:="$T$" & i, MaxMinVal:=3, ValueOf:=0, ByChange:="$V$" & i, EngineDesc:="GRG Nonlinear"
    SolverSolve UserFinish:=True
    Next
    SolverSolve (True)
    SolverSolve UserFinish:=True
    SolverFinish KeepFinal:=1
    
End Sub

Upvotes: 1

Related Questions