【发布时间】: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?