【问题标题】:How to find cells that contain specific text then hide the entire row如何查找包含特定文本的单元格然后隐藏整行
【发布时间】:2015-04-25 00:03:24
【问题描述】:

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

单元格示例PM-TR Training.doc

这就是我现在所拥有的,我可以用什么替换 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

【问题讨论】:

  • 我在发布之前看到了这个问题,但我真的不明白如何让它适用于我的情况。现在我要感谢 user3561813
  • 你本可以在你的问题中提到它,以便在实施方面获得更好的帮助,但重要的是你现在明白了
  • 下次一定会做的,谢谢。
  • 自动过滤器有用吗?为什么要使用 VBA?

标签: vba excel hide document


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 2019-03-04
    • 2020-12-24
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    相关资源
    最近更新 更多