VBa conditional delete loop not working

前端 未结 4 624
滥情空心
滥情空心 2020-11-29 12:42

I am running the following code on a spreadsheet:

Do While i <= 100000
    If Not Cells(i, 4) = \"String\" Then
        Cells(i, 4).EntireRow.Delete
    E         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 13:04

    Autofilter code:

    Sub QuickCull()
        Dim rng1 As Range
    
        Set rng1 = Range([d4], Cells(Rows.Count, "D").End(xlUp))
        ActiveSheet.AutoFilterMode = False
    
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
        End With
    
        With rng1
            .AutoFilter Field:=1, Criteria1:="<>string"
            If rng1.SpecialCells(xlCellTypeVisible).Count > 1 Then _
            .Offset(1, 0).Resize(rng1.Rows.Count - 1).Rows.Delete
        End With
    
        With Application
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
    
        ActiveSheet.AutoFilterMode = False
    End Sub
    

提交回复
热议问题