根据该行单元格中的文本删除整行

我正在尝试使用VBA来删除基于同一行的单元格的大致内容的整个行。 我已经find了确切的内容:

Sub DeleteRowBasedOnOwner() Dim RowToTest As Long For RowToTest = Cells(Rows.Count, 5).End(xlUp).Row To 2 Step -1 With Cells(RowToTest, 5) If .Value = "John" _ Or .Value = "Jerry" _ Or .Value = "Steve" _ Or .Value = "Robert" _ Or .Value = "Sarah" _ Or .Value = "Leonard" _ Or .Value = "Darryl" _ Or .Value = "Mike" _ Or .Value = "Martin" _ Then _ Rows(RowToTest).EntireRow.Delete End With Next RowToTest End Sub 

但是,通配符在这里似乎不起作用。 例如,我试过了:

 If .Value = "Jo*" _ Or .Value = "*err*" _ 

但是这不起作用。 我希望有人能帮助我。

你可以使用“like”而不是“=”。

  If .Value like "Jo*" _ Or .Value like "*err*" _