How to Delete Rows in Excel Worksheet based on a Criteria

前端 未结 4 1613
抹茶落季
抹茶落季 2021-01-25 11:19

I have an excel workbook, in worksheet1 in Column A, IF the value of that column = ERR I want it to be deleted (the entire row), how is that possible?

PS: keep in mind t

4条回答
  •  北海茫月
    2021-01-25 12:04

    Assuming there are always values in the cells in column A and that the data is in the first sheet, then something like this should do what you want:

    Sub deleteErrRows()
        Dim rowIdx As Integer
        rowIdx = 1
    
        Dim ws As Worksheet
        Set ws = ThisWorkbook.Sheets(1)
    
        While ws.Cells(rowIdx, 1).Value <> ""
            If ws.Cells(rowIdx, 1).Value = "ERR" Then
                ws.Cells(rowIdx, 1).EntireRow.Delete
            Else
                rowIdx = rowIdx + 1
            End If
        Wend
    End Sub
    

提交回复
热议问题