For-Schleife endet zu früh
15.12.2020 13:19:23
Sybot
ich habe ein Problem mit einer For-Schleife. Die Schleife soll 6 mal durchlaufen werden, aber sie endet bereits nach dem 5. Durchlauf. Da der ganze Code viel zu lange wäre und außerdem auf ein anderes Program via COM-Schnittstelle zugreift, habe ich nur die betreffende Schleife unten angegeben. Die Variable intAnzStellen wird auf 6 gesetzt. Der Code läuft bis II = 4 wie gedacht durch. Beim erreichen des Next II wird der Wert für II auch auf 5 erhöht, nur die Schleife wird nicht erneut durchlaufen. Kann sich da irgendjemand einen Reim drauf machen?
For II = 0 To intAnzStellen - 1
'ermittelt die Anzahl der auszugebenden Stäbe
intAnzStaebe = WorksheetFunction.CountIf(wksSteuerung.Range(wksSteuerung.Cells( _
conListeZeile1, conListeSpalte1 - 1), _
wksSteuerung.Cells(conListeZeile1 + conStaebeMAX, conListeSpalte1 - 1)), "Stelle " & _
II + 1)
ReDim strEKs(intAnzStaebe - 1, 0)
For JJ = 0 To intAnzStaebe - 1
strEK1 = listeInArray(wksSteuerung.Cells(conListeZeile1 + JJ + intStartZStelle, _
conListeSpalteEKs).Value)
If Not wksSteuerung.Cells(conListeZeile1 + JJ + intStartZStelle, conListeSpalteEKs). _
Value = "" Then
If UBound(strEK1) > UBound(strEKs, 2) Then ReDim Preserve strEKs(intAnzStaebe - _
1, UBound(strEK1))
For KK = 0 To UBound(strEK1)
strEKs(JJ, KK) = strEK1(KK)
Next KK
End If
Next JJ
For JJ = 0 To intAnzStaebe - 1
For KK = 0 To UBound(strEKs, 2)
If strEKs(JJ, KK) "" Then
For Each wks In ThisWorkbook.Sheets
If wks.Name = "Stelle " & II + 1 & " - " & strEKs(JJ, KK) Then GoTo _
weiter3
Next
ReDim intEKPos(UBound(intEKPos) + 1)
ReDim Preserve strEK2(UBound(strEK2) + 1)
strEK2(UBound(strEK2) - 1) = strEKs(JJ, KK)
wksT1.Visible = True
wksT1.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Set wksErg = ThisWorkbook.ActiveSheet
wksErg.Name = "Stelle " & II + 1 & " - " & strEKs(JJ, KK)
wksT1.Visible = False
End If
weiter3:
Next KK
Next JJ
intStartZStelle = intStartZStelle + JJ
Next II