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

时间:2021-06-08 22:18:16

I am trying to use VBA in order to delete an entire row based on the approximate content of a cell of that same row. I have found this for the exact content:

我试图使用VBA,以便根据同一行的单元格的大致内容删除整行。我找到了这个确切的内容:

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

However, wildcards don't seem to work here. For instance, I've tried:

但是,通配符似乎不适用于此。例如,我尝试过:

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

But this does not work. I Hope someone can help me with this.

但这不起作用。我希望有人可以帮助我。

1 个解决方案

#1


2  

You can use "like" instead of "=".

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

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

#1


2  

You can use "like" instead of "=".

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

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