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

我有一个大约4000行15列的电子表格。 我想看看是否从F2开始到F4000的单元格包含string“Class Action”。 如果是,我想保留整行; 否则,我想删除不包含“Class Action”的行。

我不知道是否重要的​​是要注意细胞将包含长长的职位说明列表,即使一行有“行动”,它可能包含其他工作,如“公司法”。 我仍然想保持行,只要“行动”是在他们的F列。

谢谢

试试这个:

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 

试试这个。

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