VBA-根据单元格是否包含特定文本来隐藏行
问题描述:
想要扫描整列以查看产品(在单个单元格中)是否可能会停用。如果停用的单词在单元格中,则情况正确。如果它被停用,我希望整行被隐藏。有什么建议么?VBA-根据单元格是否包含特定文本来隐藏行
Sub HideRows()
Dim c As Range
For Each c In Range("B3:B2452")
If InStr(1, c, "Discontinued") Or InStr(1, c, "discontinued") Then
c.EntireRow.Hidden = True
End If
Next
End Sub
答
Sub HideRows()
Dim rCheck As Range
Dim rHide As Range
Dim rCheckCell As Range
Set rCheck = ActiveWorkbook.ActiveSheet.Range("B3:B2452")
rCheck.EntireRow.Hidden = False
For Each rCheckCell In rCheck.Cells
If InStr(1, rCheckCell, "Discontinued", vbTextCompare) > 0 Then
If Not rHide Is Nothing Then Set rHide = Union(rHide, rCheckCell) Else Set rHide = rCheckCell
End If
Next rCheckCell
If Not rHide Is Nothing Then rHide.EntireRow.Hidden = True
End Sub
什么是它给你现在的行为? – SandPiper
手动输入,现在更新为复制版本。 –
现在,这不起任何作用... –