简体   繁体   English

使用 VBA 在 Excel 中隐藏/取消隐藏形状

[英]Hide/unhide shapes in Excel using VBA

在此处输入图片说明

I have 3 shapes named oval 1, oval 2 and oval 3 and I need to hide/unhide that shapes according to a value calculated from "A1" where the resulted values are 10, 20 and 30 and when oval 1 = 10, oval 2 = 20 and oval 3 = 30. The image show an error box.我有 3 个形状,名为椭圆 1、椭圆 2 和椭圆 3,我需要根据从“A1”计算的值隐藏/取消隐藏这些形状,其中结果值为 10、20 和 30,当椭圆 1 = 10 时,椭圆 2 = 20 和椭圆 3 = 30。图像显示一个错误框。 How I do this?我怎么做?

Private sub worksheet_change(byval target as range)

     If target.row = 1 and target.column = 1 then
          Me.shapes("Oval 1").Visible = (Cells(1, 1).Value = 10)

     If target.row = 1 and target.column = 1 then
          Me.shapes("Oval 2").Visible = (Cells(1, 1).Value = 20)

     If target.row = 1 and target.column = 1 then
          Me.shapes("Oval 3").Visible = (Cells(1, 1).Value = 30)
End sub

Something like this:像这样的东西:

Private sub worksheet_calculate()
     Dim v 
     v = Me.Cells(1, 1).Value
     Me.shapes("Oval 1").Visible = (v = 10)
     Me.shapes("Oval 2").Visible = (v = 20)
     Me.shapes("Oval 3").Visible = (v = 30)
End sub

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

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