I need to delete all rows (entire row) that contains a 0 or positive value in Column N. The code below does this properly but the issue is that row 1 has column headers (all text). This row gets deleted by my current macro. I need this row to not be included in the range the macro effects or locked somehow. The number of rows is dynamic and thus I cannot specify a fixed range for the macro to run on.
Sub Step20()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
For i = Range("N" & Rows.Count).End(xlUp).Row To 1 Step -1
If (Range("N" & i).Value >= 0) Then
Range("N" & i).EntireRow.Delete
End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Thanks !
You are setting your code to run from the last row until first row, which is the entire document. What if you change to run just until row 2? You would only need to make sure your headers are in row 1!
Here's what I would change in your code:
For i = Range("N" & Rows.Count).End(xlUp).Row To 2 Step -1
This way you preserve the first row and still get your job done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.