Solver in Excel (loop)

youssieboud

New Member
Joined
May 22, 2021
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone,

I'm trying to use the solver in Excel multiple times (in a loop), but I can't figure out how to do it.

I want the F19 cell as changing value and I want to set N15 to 0.10. First, I want to do this for a volume of 100 m3 (N3=100). Using the solver for this procedure works excellent. But now, I want to use the solver for increasing values of the volume, from V=100 up until V=12.000 for example, while using loops. And I also want to capture those iterated values for each step.

Can someone help me out?



r/excel - How to use solver in Excel?
r/excel - How to use solver in Excel?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Warning - this is air code...
VBA Code:
Sub Solve()

Dim i As Integer
Dim rgVol As Range
Dim rgOutput As Range

Set rgVol = Range("N3")
Set rgOutput = Range("J20")
For i = 1 To 12 Step 1

    rgVol = i * 100
    SolverOk SetCell:="$N$15", maxminval:=3, valueof:=0.1, _
    bychange:="$F$19", Engine:=1, EngineDesc:="GRG NonLinear"
    solversolve
    rgOutput.Offset(i, 0) = rgVol
    rgOutput.Offset(i, 1) = Range("$F$19").Value

Next i

End Sub

I would usually use defined names instead of cell references, and you probably want to include captions for the output values (and perhaps record more of the values), but that should get you headed in the right direction. If you need more granularity, change the number of steps ("i") and multiplier in the above.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top