删除星号字符

时间:2018-08-27 19:07:53

标签: excel vba excel-vba excel-formula

我编写了这段代码以浏览我的工作表并删除找到短语“(asterisk)Start(asterisk)”的任何行。但是,我认为星号字符的识别方式有所不同。如何更新此代码以查找原义的星号字符并删除带有该字符实例的任何行?

Sub Example()

    Dim rCell As Range
    Dim cRow As Long, lastRow As Long
    lastRow = Worksheets("Formula").Range("A" & Rows.Count).End(xlUp).row
    With Worksheets("Formula").Range("A1", Worksheets("Formula").Range("A" & Rows.Count).End(xlUp))
        Do
            Set c = .Find(What:="*Start*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns _
            , SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
            If Not c Is Nothing Then
                cRow = c.row
                c.EntireRow.Delete
            End If
         Loop While Not c Is Nothing And cRow < lastRow
    End With

End Sub

2 个答案:

答案 0 :(得分:3)

使用~进行转义:

Set c = .Find(What:="~*Start~*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns _
    , SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)

答案 1 :(得分:2)

您可以使用波浪号*之前的通配符~星号:

Set c = .Find(What:="~*Start~*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns _
        , SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)