如果 BD 列中的值为零,我创建了一个循环来删除行。循环最多可能需要半个小时。我已经看到了使用自动过滤器或创建变体数组来加快功能的建议。如果您可以为下面的代码提出更好的解决方案,请告诉我。
Const colBD As Long = 56
Dim IRow As Long
Dim LstRow As Long
LstRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
IRow = 3
'loop to delete rows with zero in colBD
Do While IRow <= LstRow
If Cells(IRow, colBD) = 0 Then
Cells(IRow, 1).EntireRow.Delete
LstRow = LstRow - 1 ' one less row
Else
IRow = IRow + 1 ' move to next row
End If
Loop
最佳答案
上面的评论是正确的,最好一次删除,但是如果循环最好从最后开始并返回。很容易陷入无限循环。
Const colBD As Long = 56
Dim IRow As Long
Dim LstRow As Long
Dim i As Integer
LstRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
IRow = 3
'Always start with the last row and work towards the first when deleting rows
For i= LstRow to IRow Step - 1
If Cells(i, colBD) = 0 Then
Cells(i, 1).EntireRow.Delete
End If
End Sub
关于excel - 改进循环以更快地删除 excel 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46077673/