Forum Discussion
roboed
Mar 30, 2022Copper Contributor
Need to run a macro multiple times
Hi. Why does not this code work? I connect the macro to a button and press it, and about half the rows with "1" in col C is deleted. Then I press it again and about 3 more rows disappear. After a few...
- Mar 30, 2022
roboed You have to loop backwards:
Sub Delete_Old() Dim r As Range For r = 1000 To 8 Step -1 If Range("C" & r).Value = 1 Then Range("C" & r).EntireRow.Delete End If Next r End Sub
HansVogelaar
Mar 30, 2022MVP
roboed You have to loop backwards:
Sub Delete_Old()
Dim r As Range
For r = 1000 To 8 Step -1
If Range("C" & r).Value = 1 Then
Range("C" & r).EntireRow.Delete
End If
Next r
End Sub