Delete Specific rows in Excel

后端 未结 2 1751
轮回少年
轮回少年 2021-01-26 00:14

I want to create a for loop to check all of the rows in a sheet that I have and want this code to be able to delete rows if they contain a specified content in certain columns (

2条回答
  •  情书的邮戳
    2021-01-26 01:03

    This will process rows 2 thru 4000, adjust to suit your needs:

    Sub RowKiller()
        Dim K As Range, rKill As Range
        Set K = Range("K2:K4000")
        Set rKill = Nothing
        For Each r In K
            v = r.Text
            If InStr(1, v, "June") > 0 Then
                If rKill Is Nothing Then
                    Set rKill = r
                Else
                    Set rKill = Union(r, rKill)
                End If
            End If
        Next r
    
        If Not rKill Is Nothing Then
            rKill.EntireRow.Delete
        End If
    End Sub
    

提交回复
热议问题