繁体   English   中英

当一个单元格中有特定值时,隐藏和取消隐藏 Excel VBA 中的行

[英]Hide and unhide rows in Excel VBA when specific value in the one cell

如果从下拉列表中选择了特定值,我想隐藏/取消隐藏。 只要它有效,它就可以在工作表代码下(选择值时)或按下按钮时。 非常感谢您的帮助。 我尝试使用此代码未成功..

Application.EnableEvents = False

If DWR.Cells(4, 14) = "CANTI" Then
    DWR.Activate
    DWR.Range("10:49").EntireRow.Hidden = False
    'must hide the empty rows
    DWR.Activate
    DWR.Range("50:89").EntireRow.Hidden = True

ElseIf DWR.Cells(4, 14) = "F100" Then
    DWR.Activate
    DWR.Range("50:89").EntireRow.Hidden = True
    'must hide the empty rows
    DWR.Activate
    DWR.Range("10:49").EntireRow.Hidden = False

End If

Application.EnableEvents = True

有什么建议么?

试试这样的东西?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B1")) Is Nothing Then

        Application.EnableEvents = False

            Range("10:89").EntireRow.Hidden = False     '~~~> Default case: display ALL rows

            If Target = "CANTI" Then
                Range("10:49").EntireRow.Hidden = False
                Range("50:89").EntireRow.Hidden = True
            ElseIf Target = "F100" Then
                Range("10:49").EntireRow.Hidden = True
                Range("50:89").EntireRow.Hidden = False
            End If

        Application.EnableEvents = True

    End If
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM