简体   繁体   English

Excel VBA:单击图像时切换行隐藏/取消隐藏

[英]Excel VBA: Toggle rows hide/unhide when image clicked

I am brand new to VBA and have an image which i want to assign a macro to so that when the user clicks it, it unhides a range of rows, and when th user clicks it again, it hides the rows.我是 VBA 的新手,并且有一个图像,我想为其分配一个宏,以便当用户单击它时,它会取消隐藏一系列行,当用户再次单击它时,它会隐藏这些行。

My image:我的形象:

Image1.jpg图片1.jpg

I have assigned the following maco to this image:我已将以下 maco 分配给此图像:

Sub sbHidingUnHideRows()
'To Hide Rows 22 to 25
Rows("9:14").EntireRow.Hidden = False
End Sub

This unhides my rows when the user clicks the image.当用户单击图像时,这会取消隐藏我的行。 But how can i make the rows hide again on the second click?但是如何在第二次单击时再次隐藏行? Like a toggle button?像一个切换按钮?

Here's what i've tried:这是我尝试过的:

Sub sbHidingUnHideRows()
'To Hide Rows 22 to 25
Rows("9:14").EntireRow.Hidden = True
Else
Rows("9:14").EntireRow.Hidden = False
End Sub

Please can someone show me where i'm going wrong?请有人告诉我我哪里出错了吗?

Thanks in advance提前致谢

try this尝试这个

Sub sbHidingUnHideRows()
    If Rows("22:25").EntireRow.Hidden = True Then
        Rows("22:25").EntireRow.Hidden = False
    Else
        Rows("22:25").EntireRow.Hidden = True
    End If
End Sub

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

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