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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,288
Members
448,885
Latest member
LokiSonic

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