Looping solver function in VBA

adustin42

New Member
Joined
Dec 2, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I am trying to loop a solver function to minimize RMSE in excel by altering the alpha, beta and gamma values of a holts winter forecast for over 300 line items. For efficiency and testing the loop is only using row 8 to 12 for the time being. When I run it, it processes for a second, but no change after that. Please advise.

1606949124480.png


Code:
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

adustin42

New Member
Joined
Dec 2, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub Macro3()
'
' Macro3 Macro
'
Dim i As Integer
ActiveWorkbook.ActiveSheet.Activate
For i = 8 To 12
SolverReset

    SolverOk SetCell:="$J$" & i, MaxMinVal:=2, ValueOf:=0, ByChange:="$G & i : $I &i", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverAdd CellRef:="$G:$I", Relation:=1, FormulaText:="1"
    SolverAdd CellRef:="$G:$I", Relation:=3, FormulaText:="0"
    SolverOk SetCell:="$J$" & i, MaxMinVal:=2, ValueOf:=0, ByChange:="$G & i : $I &i", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverOk SetCell:="$J$" & i, MaxMinVal:=2, ValueOf:=0, ByChange:="$G & i : $I &i", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
        
    SolverSolve True
    Next i
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,372
Messages
5,635,880
Members
416,886
Latest member
coreyalaurence37

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
Top