Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1628to1632
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Spalten Schleife für Solver Makro stoppt bei BA

Spalten Schleife für Solver Makro stoppt bei BA
09.06.2018 15:34:47
Simon
Liebe VBA-Profis
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

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Spalten Schleife für Solver Makro stoppt
12.06.2018 09:33:53
Daniel
Hi
was müsste denn in der Zelle stehen?
bzw was steht in der Zelle in den Spalten, bei denen der Code problemlos läuft?
vermutlich Zahlen, da du mit dem Solver arbeitest.
da hilft dann im Prinzip folgende IF-Abfrage, um solche fehlerhaften Spalten zu überspringen:

For iCol = iColFirst To (iColFirst + iColJump)
if VarType(Cells(?, iCol).value) = 5 Then
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)
end if
Next iCol
Gruß Daniel
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige