1
当按下按钮时,我想遍历表单中的所有单元格并查找包含.doc或.xls或.pdf的单元格,并隐藏整个行。 我知道我不能使用Contains
,但必须有类似的东西。如何查找包含特定文本的单元格,然后隐藏整行
细胞例如PM-TR Training.doc
这是我现在我可以代替包含?
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
可能重复[检查是否一个字符串包含另一个字符串(http://stackoverflow.com/questions/15585058/check-if-a-string-contains-another-string) – 2015-02-23 15:50:20
我看到了这个问题,发布之前,但我真的不知道如何使它适用于我的情况。现在我非常感谢user3561813 – phil652 2015-02-23 16:06:58
你可以在你的问题中提到它,以便在实现中获得更好的帮助,但重要的是你现在明白了 – 2015-02-23 16:09:32