【问题标题】:VBA- Hide rows based on whether cell contains specific textVBA-根据单元格是否包含特定文本隐藏行
【发布时间】:2017-08-09 15:20:18
【问题描述】:

希望扫描一整列以查看产品(在单个单元格中)是否可能停产。如果单词discontinued 在一个单元格中,这是正确的。如果停产,我希望将整行隐藏起来。有什么建议吗?

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

【问题讨论】:

  • 它现在给你的行为是什么?
  • 已手动输入,现已更新为复制版本。
  • 现在,这没有任何作用......
  • 我刚试过这个,它对我有用。
  • @RonanGarrison 你为什么不使用过滤器???会更快

标签: vba excel multiple-columns cells


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2015-04-25
    • 2016-01-11
    • 2019-06-16
    相关资源
    最近更新 更多