Link to home
Start Free TrialLog in
Avatar of Rayne
RayneFlag for United States of America

asked on

Hide button on condition Excel

I have included the worksheet change code as well. So anytime, the worksheet [some] is hidden, the button [btn-1] is hidden. So if worksheet [some] is unhidden, then we can see button [btn_1] visible.
I have a code that’s working but I want it to be very good and never break – because it’s very very important to hide the button when sheet some is hidden – any suggestions or improvements is greatly appreciated. And I want to make sure I am doing that the right way.

Sub Worksheet_Change(ByVal target As Range)
   
    HideOnCondition
   
End Sub

Sub HideonCondition()

'if worksheet [some] is visible, only then show button [btn_1]
If (Sheet2.Visible = xlSheetVisible) Then
   ActiveSheet.Shapes("btn_1").Visible = True
Else
   ActiveSheet.Shapes("btn_1").Visible = False
End If

     
End Sub
hideButtononCondition.xlsm
SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rayne

ASKER

Thank you Dave, Byundt and Martin,

thank you all for confirming. I justed wanted to make sure I am doing it right. Further, Dave - the workbook selection event was perfect....I cant ask for more :)