Home > OS >  Loop function VBA : compile error named argument already specified
Loop function VBA : compile error named argument already specified

Time:09-14

I’m trying to make this solver’s constraints repeat for over a hundred lines, I know nothing about coding, pls help, what am I doing wrong?

Sub MultipleSolver()
Dim i As Integer
ActiveWorkbook.ActiveSheet.Activate
For i = 6 TO 132
SolverReset
SolverOk SetCell:="$AJ$" & i, MaxMinVal:=2, ByChange: ="$AA$" & i
SolverAdd CellRef:-"$AJ$” & i, Relation:=1,
CellRef:="$AK$" & i
SolverAdd CellRef:-"$AA$" & i, Relation:=-4, FormulaText:-"integer"

SolverSolve True
Next i
End Sub

CodePudding user response:

I try to modify a little bit to make the program runable: I corrected some :- to :=, "$AJ$” to "$AJ$" and there is two CellRef:= in the first SolverAdd, so I disable the second one by'. To make it functional correct, you need to do it yourself.

Sub MultipleSolver()
Dim i As Integer
ActiveWorkbook.ActiveSheet.Activate
For i = 6 To 132
SolverReset
SolverOk SetCell:="$AJ$" & i, MaxMinVal:=2, ByChange:="$AA$" & i
SolverAdd CellRef:="$AJ$" & i, Relation:=1     
',CellRef:="$AK$" & i
SolverAdd CellRef:="$AA$" & i, Relation:=-4, FormulaText:="integer"

SolverSolve True
Next i
End Sub

CodePudding user response:

i did this and its giving me no error but its not working either

Sub MultipleSolver()
Dim i As Integer
ActiveWorkbook.ActiveSheet.Activate
For i = 6 To 132
SolverReset
SolverOk SetCell:="$AJ$" & i, MaxMinVal:=2, ByChange:="$AA$" & i
SolverAdd CellRef:="$AJ$" & i, Relation:=1, FormulaText:="$AK$" & i
SolverAdd CellRef:="$AA$" & i, Relation:=-4, FormulaText:="integer"

SolverSolve (True)
Next i
End Sub
  • Related