For Each loop won't delete all rows with specific values

前端 未结 2 1213
臣服心动
臣服心动 2021-01-07 13:42

I want to delete all rows that do not contain the value \"Total\" in Range(\"B11:B25\").

Below is my code.

Dim cell As Range

For Each cell In Range(         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 14:17

    try this, it will loop from row 25 to 11 backwards and find anything not "Total"

    Dim i As Integer
    For i = 25 To 11 Step -1 ' change to whatever row you want
        If Range("B" & i) <> "Total" Then
            Range("B" & i).EntireRow.Delete
        End If
    Next
    

提交回复
热议问题