How to delete rows in Excel based on criteria using VBA?

前端 未结 4 756
花落未央
花落未央 2020-11-29 12:35

I am currently building a macro to format a sheet of data as well as to remove inapplicable rows of data. Specifically, I am looking to delete rows where Column L = \"ABC\"

4条回答
  •  失恋的感觉
    2020-11-29 12:59

    Cell with number 12 is "L" and number 27 is "AA"

    Dim x As Integer
    
    x = 1
    
    Do While x <= ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    
        If (Cells(x, 12) = "ABC") Then
        ActiveSheet.Rows(x).Delete
        Else
            If (Cells(x, 27) <> "DEF") And (Cells(x, 27) <> "") Then
            ActiveSheet.Rows(x).Delete
            Else
            x = x + 1
            End If
        End If
    
    Loop
    
    End Sub
    

提交回复
热议问题