I run this code to delete rows which have have > -100. However it keeps looping and never stops.
What am I missing here?
For i = 2 To 500
If Worksheets("Sales").Cells(i, 3).Value > -100 Then
Worksheets("Sales").Cells(i, 3).EntireRow.Delete
i = i - 1
End If
Next i
Option 1: Hold the Esc key down for more than a few seconds. Option 2: Press CTRL+BREAK. Option 3: CTRL + ALT + DEL to end process & have Auto recover when you re-open.
If the Macro is simply in a continuous loop or is running for too long you can use one of these keyboard shortcuts to kill it: Esc hit the Escape key. Ctrl + Break hit Ctrl key and then the break key, which is also the pause key.
We can exit any Do loop by using the Exit Do statement.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With