I am stepping through and deleting marked rows in my sheet. If I miss the header row the macro runs but fails to delete one highlighted row.
If I include my header, I get a run time error.
I have fixed it my including i = 1 before the loop
...but I cannot get my head around my it fails.
This one missed one of the flagged "DEL" rows"
This one gives a runtime error
This one works
If I include my header, I get a run time error.
I have fixed it my including i = 1 before the loop
...but I cannot get my head around my it fails.
This one missed one of the flagged "DEL" rows"
Code:
Set rng = Sheets("Stage 2").Range("[COLOR=#ff0000]F2[/COLOR]", Sheets("Stage 2").Range("F5000").End(xlUp))
For counter = 1 To rng.Rows.Count
If rng.Cells(i) = "DEL" Then
rng.Cells(i).EntireRow.Delete
Else
i = i + 1
End If
Next
This one gives a runtime error
Code:
Set rng = Sheets("Stage 2").Range("[COLOR=#ff0000]F1[/COLOR]", Sheets("Stage 2").Range("F5000").End(xlUp))
For counter = 1 To rng.Rows.Count
If rng.Cells(i) = "DEL" Then
rng.Cells(i).EntireRow.Delete
Else
i = i + 1
End If
Next
This one works
Code:
Set rng = Sheets("Stage 2").Range("[COLOR=#ff0000]F1[/COLOR]", Sheets("Stage 2").Range("F5000").End(xlUp))
[COLOR=#ff0000] i = 1[/COLOR]
For counter = 1 To rng.Rows.Count
If rng.Cells(i) = "DEL" Then
rng.Cells(i).EntireRow.Delete
Else
i = i + 1
End If
Next
Last edited: