根据 Col N 条件删除整行

Delete Entire Rows Based on Col N Criteria

如果 Col N 中的单元格包含单词 "Completed".

,我无法弄清楚为什么以下代码不会删除整行
Sub DeleteRowBasedOnCriteria()    
Dim RowToTest As Long    

For RowToTest = Cells(Rows.Count, 14).End(xlUp).Row To 2 Step -1    

With Cells(RowToTest, 14)    
    If .Value <> "Completed" _    
    Then _    
    Rows(RowToTest).EntireRow.Delete    
End With    

Next RowToTest    

End Sub   

后续问题:

Sub DeleteRowBasedOnCriteria()
    Dim RowToTest As Long

    For RowToTest = Cells(Rows.Count, 14).End(xlUp).Row To 2 Step -1
        With Cells(RowToTest, 14)
            If .Value <> "Completed" Then Rows(RowToTest).EntireRow.Delete
        End With
    Next RowToTest

End Sub

这个建议是极简主义的,但是...

子 DeleteRowBasedOnCriteria()
昏暗的 RowToTest 只要

对于 RowToTest = Cells(Rows.Count, 14).End(xlUp).Row To 2 Step -1

有单元格(RowToTest,14)
如果.Value <> "Completed" _
那么_
.EntireRow.Delete

结尾

下一行测试

结束子

我终于用下面的代码让它工作了:

子 DeleteRowBasedOnCriteria2()
工作表("InProcess").Select

  Dim RowToTest As Long  

  For RowToTest = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1  
      With ActiveSheet.Cells(RowToTest, 14)  
          If .Value = "Completed" Then ActiveSheet.Rows(RowToTest).EntireRow.Delete   
    End With  
  Next RowToTest  

结束子