vba 如何查找包含特定文本的单元格然后隐藏整行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28677607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:20:00  来源:igfitidea点击:

How to find cells that contain specific text then hide the entire row

excelvbaexcel-vbahidedocument

提问by phil652

When a button is pressed I want to loop through all the cells in my Sheet and find the cells that contains .doc or .xls or .pdf and hide the entire Row. I know I can't use Containsbut there must be something similar.

当按下按钮时,我想遍历工作表中的所有单元格并找到包含 .doc 或 .xls 或 .pdf 的单元格并隐藏整个行。我知道我不能使用,Contains但必须有类似的东西。

Cell example PM-TR Training.doc

单元格示例 PM-TR Training.doc

This is what I have for now what can I replace contains with?

这就是我现在所拥有的,我可以用什么来替换 contains ?

Sub HideRows()
    Dim cell As Range
    Dim DataCount As Integer
    'Change the sheet name as necessary in the following line
    With Worksheets("Sheet1")
        DataCount = Range("A" & Rows.Count).End(xlUp).Row
        For Each cell In Range("A1:A" & DataCount)
            If cell.Contains(".doc") Or cell.Contains(".xls") Or cell.Contains(".pdf") Then
                'The following code assumes you want the row hidden.
                Range(cell.Row).EntireRow.Hidden = True
            End If
        Next cell
    End With
End Sub

回答by user3561813

The function InStr withing your IFstatement should do the trick.

IF语句中的函数 InStr应该可以解决问题。

IF instr(cell.value, ".doc")> 0 then
    'Code Here