Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7199

excel crashes between end with and for loop?

$
0
0

Adding a row randomly crashes my excel.

  • Crashes can happen at end with or for rij = 4 to lastRow.

  • Debugging very fast through the lines makes the program crash faster compared to taking 30 seconds of pause between the lines.

  • I have the exact same code in a different module and it does work there.

  • lastrow has the value 5 when I debug it, so the problem can't be Rij > lastRow

code:

Option ExplicitDim lastRow As LongDim IngevuldeCellen As IntegerDim Ingevuld As IntegerDim Rij As IntegerDim tbl As ObjectDim AantalRijen As IntegerDim laatsteRij As LongPrivate Sub WorkSheet_Change(ByVal Target As Range)'Als laatste rij 6 ingevulde velden heeft doe dit    lastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row    IngevuldeCellen = WorksheetFunction.CountA(Range("B" & lastRow & ":G" & lastRow))    If IngevuldeCellen >= 4 Then        Call Module3.AddRowToBottom        Range("F1:F" & lastRow).Interior.Color = RGB(59, 148, 0)        Range("A1:A" & lastRow).Interior.Color = RGB(59, 148, 0)    ElseIf IngevuldeCellen < 4 Then    Range("A" & lastRow).Interior.Color = RGB(255, 0, 0)    Range("F" & lastRow).Interior.Color = RGB(255, 0, 0)    End If    Ingevuld = WorksheetFunction.CountA(Range("H6:O18"))    If Ingevuld >= 10 Then        With Sheets("Ruimtelijst")            lastRow = .Cells(Cells.Rows.Count, "G").End(xlUp).Row        End With        For Rij = 4 To lastRow            If Not Intersect(Target, Blad3.ListObjects("tbl_" & Rij - 3).Range) Is Nothing Then'Zoek de laatste rij van de tabel op                Set tbl = Blad3.ListObjects("tbl_" & Rij - 3)                AantalRijen = tbl.Range.Rows.Count                laatsteRij = tbl.Range.Cells(AantalRijen, "E").Row'Roept module                Call Module3.AddRow(laatsteRij)            End If        Next Rij    End IfEnd Sub

Viewing all articles
Browse latest Browse all 7199

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>