Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如果单元格包含指定的字,则删除行_Vba - Fatal编程技术网

Vba 如果单元格包含指定的字,则删除行

Vba 如果单元格包含指定的字,则删除行,vba,Vba,如果a列中的任何单元格包含“总计”一词,是否有人知道删除整行的vba代码?例如,A38包含“总计”,删除整行。下个月,单元格A44包含单词“total”,删除整行。等等谢谢大家! 对下面的内容进行测试,看看它是否接近您想要的内容 Sub TestDeleteRows() Dim rFind As Range Dim rDelete As Range Dim strSearch As String Dim iLookAt As Long Dim bMatchCase As Boolean str

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

对下面的内容进行测试,看看它是否接近您想要的内容

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

因此,您希望“循环”所有“第1行第1列中的单元格”,并检查“Cells.Value”以查看单词total是否为“InStr”,它将返回大于0的值。然后获取Cells.EntireRow.Delete。如果你尝试一下,应该不会太难。这可能会有帮助。另一种使用