I am having some trouble trying to loop the Solver for "ma" varying from 2 to "n"a in the code below, in which "ma" is a preset number which is equal the number of columns in the sheet "Dados Brutos - A". The problem happens by the time I try to configure the argument "ByChange". I want to define there a range from cells column "na" (A, B, C and so on) and rows 6, 7 and 8. Can anybody help me? I've attached a print to show what exactly I am aiming to do.
Edit:
The code below solved the problem, thanks to Алексей Р. Hope this post helps anyone else having the same problem.
Sub AjustarCurvas_A()
'
' Ajusta equações de segundo grau às amostras selecionadas
'
'
Dim na As Integer, ma As Integer
Sheets("Dados Brutos - A").Select
na = Cells.Find(What:="*", SearchDirection:=xlPrevious).Column
Sheets("Det. Ruído - A").Select
With ActiveSheet
For ma = 2 To na
SolverOk SetCell:=.Cells(2, ma), MaxMinVal:=2, ValueOf:=0, ByChange:=.Cells(6, ma).Resize(3), _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next ma
End With
End Sub
Here are prints of sheets "Dados Brutos - A" and "Det. Ruído - A"
What I did was count how many columns I had on "Dados Brutos - A" and called that number "na". Then I used the solver ("na" - 1) times to vary the values on cells (B6:B9) and optimize the value calculated from them on cell B14. Then (C6:C9) to optimize C14 and so on, until I reached column CN, in that specific case.