Forum Discussion

roboed's avatar
roboed
Copper Contributor
Mar 30, 2022
Solved

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...
  • HansVogelaar's avatar
    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

Resources