0

如果A列中的任何单元格包含“Total”一词,是否有人知道删除整行的vba代码?例如,A38 包含“总计”,删除该整行。下个月,单元格 A44 包含单词“total”,删除整行。等等……谢谢!

4

1 回答 1

0

给下面的一个测试运行,看看它是否接近你想要的。

Sub TestDeleteRows()
Dim rFind As Range
Dim rDelete As Range
Dim strSearch As String
Dim iLookAt As Long
Dim bMatchCase As Boolean

strSearch = "Total"

iLookAt = xlPart 'Change to xlWhole if the entire cell must equal search string
bMatchCase = False  'Change to True if you want search to be case sensitive

Set rDelete = Nothing

Application.ScreenUpdating = False

With Sheet1.Columns("A:A")
    Set rFind = .Find(strSearch, LookIn:=xlValues, LookAt:=iLookAt, SearchDirection:=xlPrevious, MatchCase:=bMatchCase)
    If Not rFind Is Nothing Then
        Do
            Set rDelete = rFind
            Set rFind = .FindPrevious(rFind)
            If rFind.Address = rDelete.Address Then Set rFind = Nothing
            rDelete.EntireRow.Delete
        Loop While Not rFind Is Nothing
    End If
End With
Application.ScreenUpdating = True
End Sub
于 2013-10-28T19:38:38.977 回答