[Solved] How to delete rows based on condition in VBA? [duplicate]


The issue is that once a row has been deleted, the macro will continue onto the next row (skipping a row).

Working backwards through the loop will prevent any rows being missed so something like:

Sub DeleteRowsPiuDi40Mega()

Dim LastRow As Long
Dim ws4 As Worksheet

Set ws4 = ActiveWorkbook.Sheets("atm_hh")
LastRow = ActiveSheet.Range("C" & ActiveSheet.Rows.Count).End(xlUp).Row

For i = LastRow to 2 Step -1
    If Cells(i, 3) > 40 Then Rows(i & ":" & i).EntireRow.Delete
Next i

End Sub

1

solved How to delete rows based on condition in VBA? [duplicate]