隐藏形状取决于单元格值

时间:2017-06-05 16:24:48

标签: excel vba shapes

我使用以下代码根据单元格值隐藏/取消隐藏某些形状。隐藏/显示正在工作,但形状作为链接工作,当我点击其中一些时,它只是改变并开始同时显示所有形状。 有没有更好的代码来做到这一点?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$50" Then
        'AAA
        Shapes("XXX1").Visible = Target.Value = "ABC"
        Shapes("XXX2").Visible = Target.Value = "ABC"
        Shapes("XXX3").Visible = Target.Value = "ABC"
       'BBB
        Shapes("YYY1").Visible = Target.Value = "DEF"
       'CCC
        Shapes("ZZZ1").Visible = Target.Value = "GHI"
        Shapes("ZZZ2").Visible = Target.Value = "GHI"
        Shapes("ZZZ3").Visible = Target.Value = "GHI"

    End If
End Sub

0 个答案:

没有答案