[英]How to delete entire row when cell contains specific value but NOT effect row 1
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).我需要删除列 N 中包含 0 或正值的所有行(整行)。下面的代码正确执行此操作,但问题是第 1 行具有列标题(所有文本)。 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?
如果您更改为仅运行到第 2 行会怎样? You would only need to make sure your headers are in row 1!
您只需要确保您的标题在第 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.这样您就可以保留第一行并仍然完成您的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.