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.
My image:
Image1.jpg
I have assigned the following maco to this image:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.