删除列F中不包含字符串“Class Action”的所有行

时间:2014-07-09 18:09:59

标签: excel excel-vba vba

我有一个大约有4000行和15列的电子表格。我想看看是否从F2到F4000的单元格包含字符串" Class Action"。如果是的话,我想保留整行;否则,我想删除不包含" Class Action"。

的行

我不知道是否重要的​​是要注意单元格将包含很长的作业描述列表,所以即使一行有" Class Action"它可能包含其他工作,例如"公司法"。我仍然希望保留行,只要" Class Action"在他们的F栏中。

由于

2 个答案:

答案 0 :(得分:1)

尝试一下:

Sub RowKiller()
    Dim F As Range, rKill As Range
    Set F = Range("F2:F4000")
    Set rKill = Nothing
    For Each r In F
        v = r.Text
        If InStr(1, v, "Class Action") = 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

答案 1 :(得分:0)

试一试。

Sub KeepClassA()

'get how many rows we have in column f
irows = Cells(Rows.Count, "F").End(xlUp).Row

'loop thru rows
For i = irows To 2 Step -1
'check if value does not contain Class ACtion
If Cells(i, 6).Value <> "Class Action" Then
'delete the row if true.
Cells(i, 6).EntireRow.Delete

End If
Next i


End Sub
相关问题