Question : Why does this code need rebooting?

I've attached a piece of code that does work, especially as I step it through its sequence.  However, when I press the run button, it will continue to work  for a few more lines, then stop.  Once I manually start it, the code will continue to work for a few more lines on its own.  It's confusing as to why it'll just stop.  Yes, the With Sheets could be combined, but its late and I just left it as is.  However, I wouldn't think that would cause the misfire.

Would anyone have an answer?

Cook
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Option Explicit

Sub DelUnNeeded()
Dim rng As Range, lPos As Range
Dim celle As Range, wks As Worksheet
Dim i As Long, FinalRow As Range
Dim c As Long


With Sheets("PIDs")
    Set rng = Range(.Cells(4, "H"), .Cells(.Rows.Count, "H").End(xlUp))
End With

i = 4
On Error Resume Next
With Sheets("PIDs")
     For Each celle In rng
           If Cells(i, 8) = "VACANT POSITION" Then Rows(i).Delete
            Set lPos = Cells(i, 11)
           If Left(lPos, 11) = "115528" Then Rows(i).Delete
           If Left(lPos, 11) = "124957" Then Rows(i).Delete
        i = i + 1
    Next
 End With

End Sub

Answer : Why does this code need rebooting?

Oops I missed the obvious error - see below:

If Left(.Cells(i, 11), 11) = "115528" Then .Rows(i).EntireRow.Delete
If Left(.Cells(i, 11), 11) = "124957" Then .Rows(i).EntireRow.Delete

should have been:

If Left(.Cells(i, 11), 6) = "115528" Then .Rows(i).EntireRow.Delete
If Left(.Cells(i, 11), 6) = "124957" Then .Rows(i).EntireRow.Delete
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Sub DelUnNeeded()
Dim FinalRow As Long, i As Long, lPos As Long

With Sheets("PIDs")
    FinalRow = .Cells(.Rows.Count, "H").End(xlUp).Row
    For i = lastrow To 4 Step -1
        If UCase(.Cells(i, 8)) = "VACANT POSITION" Then .Rows(i).EntireRow.Delete
        If Left(.Cells(i, 11), 6) = "115528" Then .Rows(i).EntireRow.Delete
        If Left(.Cells(i, 11), 6) = "124957" Then .Rows(i).EntireRow.Delete
    Next i
End With

End Sub
Random Solutions  
 
programming4us programming4us