Code in VBA loops and never ends. How to fix this?

Maybe you could union the rows and delete them at once? Something like this (untested).

Dim myRow As Range
Dim toDelete As Range

For i = 2 To 500
    If Worksheets("Sales").Cells(i, 3).Value > -100 Then
       Set myRow = Worksheets("Sales").Rows(i)
       If toDelete Is Nothing Then
            Set toDelete = myRow
        Else
            Set toDelete = Union(toDelete, myRow)
        End If
    End If
Next i

If Not toDelete Is Nothing Then _
    toDelete.Delete

Leave a Comment