Ich halte mich kurz. Ich habe das identische Problem wie dieser Beitrag im Archiv: https://www.herber.de/forum/archiv/1312to1316/1313078_Spalten_Schleife_fuer_Solver_Makro.html
Mein Code ist etwas länger, weil ich die Schleife x-mal durchführen muss.
Problem:
Das Makro stoppt exakt bei Spalte "BA", was Spalte Nr. "53" entspricht, obschon die Schlaufe bis Nr. "155" laufen müsste. Gehe davon aus, dass das Problem darin liegt: die Nummer 53 (Spalte "BA") gibt im Excel den Wert "A[" zurück.
Wie kann ich das Problem beheben?
Vielen Dank für Eure spitzen Unterstützung!
Hier mein Code:
Sub Makro1()
' Makro1 Makro
Const iColFirst As Long = 2
Const iColJump As Long = 155
Dim iCol As Long
SolverReset
For iCol = iColFirst To (iColFirst + iColJump)
SolverAdd CellRef:=Cells(51, iCol).Address, Relation:=1, FormulaText:="1"
SolverAdd CellRef:=Cells(52, iCol).Address, Relation:=1, FormulaText:="1"
SolverOk SetCell:=Cells(46, iCol).Address, MaxMinVal:=2, ValueOf:=0, ByChange:=Range(Cells( _
51, iCol), (Cells(52, iCol))), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next iCol
SolverReset
For iCol = iColFirst To (iColFirst + iColJump)
SolverAdd CellRef:=Cells(53, iCol), Relation:=1, FormulaText:="1"
SolverAdd CellRef:=Cells(54, iCol), Relation:=1, FormulaText:="1"
SolverOk SetCell:=Cells(47, iCol), MaxMinVal:=2, ValueOf:=0, ByChange:=Range(Cells(53, iCol) _
, (Cells(54, iCol))), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next iCol
SolverReset
For iCol = iColFirst To (iColFirst + iColJump)
SolverAdd CellRef:=Cells(55, iCol), Relation:=1, FormulaText:="1"
SolverAdd CellRef:=Cells(56, iCol), Relation:=1, FormulaText:="1"
SolverOk SetCell:=Cells(48, iCol), MaxMinVal:=2, ValueOf:=0, ByChange:=Range(Cells(55, iCol) _
, (Cells(56, iCol))), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next iCol
SolverReset
For iCol = iColFirst To (iColFirst + iColJump)
SolverAdd CellRef:=Cells(57, iCol), Relation:=1, FormulaText:="1"
SolverAdd CellRef:=Cells(58, iCol), Relation:=1, FormulaText:="1"
SolverOk SetCell:=Cells(49, iCol), MaxMinVal:=2, ValueOf:=0, ByChange:=Range(Cells(57, iCol) _
, (Cells(58, iCol))), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next iCol
SolverReset
For iCol = iColFirst To (iColFirst + iColJump)
SolverAdd CellRef:=Cells(59, iCol), Relation:=1, FormulaText:="1"
SolverAdd CellRef:=Cells(60, iCol), Relation:=1, FormulaText:="1"
SolverOk SetCell:=Cells(50, iCol), MaxMinVal:=2, ValueOf:=0, ByChange:=Range(Cells(59, iCol) _
, (Cells(60, iCol))), Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve (True)
Next iCol
End Sub