Find all and delete in VBA

别等时光非礼了梦想. 提交于 2019-12-02 10:13:34

As follows up from chat, this code is working:

Sub test()
    Dim firstAddress As String
    Dim c As Range
    Dim rngToDelete As Range

    With Worksheets(5).Range("c1:c1500")
       Set c = .Find("-", LookIn:=xlValues)
       If Not c Is Nothing Then
           firstAddress = c.Address
           Do
               If rngToDelete Is Nothing Then
                  Set rngToDelete = c
               Else
                  Set rngToDelete = Union(rngToDelete, c)
               End If
               Set c = .FindNext(c)
               If c Is Nothing Then Exit Do
           Loop While c.Address <> firstAddress
       End If
    End With

    If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!