Hide shape with command button

SaraWitch

Active Member
Joined
Sep 29, 2015
Messages
322
Office Version
  1. 365
Platform
  1. Windows
Hello peeps,

I found a couple of formulas to make a shape disappear and reappear based on cell data. I have inserted a Check Box and linked it to cell U11. The formulas are in the sheet VBA but neither are working and I'm not sure what I'm doing wrong...? (I've renamed my shape to 'InstructionsCover'.)

VBA 1:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$U$11" Then
Sheet2.Shapes("InstructionsCover").Visible = True
Else
Sheet2.Shapes("InstructionsCover").Visible = False
End If
End Sub

VBA 2:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("$U$11") = "FALSE" Then
Sheet2.Shapes("InstructionsCover").Visible = msoTrue
End If
If Range("$U$11") = "TRUE" Then
Sheet2.Shapes("InstructionsCover").Visible = msoFalse
End If
End Sub

Any help would be appreciated :giggle:
 
Like "My Aswer Is This" alluded to, you should try things yourself also.
Just blindly copying code without knowing how it works does not do you any good and makes it very difficult to change to fit your needs at a later stage.
I think it is generally known as "You have to learn by trial and error"
Enough of my rambling. If you want to use a shorter version, try this.
Code:
Private Sub CheckBox1_Click()
    ActiveSheet.Shapes("InstructionsCover").Visible = IIf(CheckBox1.Value = True, True, False)
End Sub
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You could also use this:
VBA Code:
Private Sub CheckBox1_Click()
ActiveSheet.Shapes("InstructionsCover").Visible = Not ActiveSheet.Shapes("InstructionsCover").Visible

End Sub
 
Upvote 0
Join the club.
I think that some of that can be a problem. Obviously people are happy when getting a solution but if you don't understand how it works it could turn into grief.
And beside that, hard to change if needed.
On the other hand, people ought to familiarize themselves with the suggested solutions for that reason.
People will be people.
 
Upvote 0
Thank you, folks. I do understand most of the code which has been offered as a solution (and I thought that the benefit of these forums is to ask for those of us who have not been trained or are not as skilled as others! :unsure: ), but nothing seems to be working for me. So, I have done a workaround by having two option buttons and assigning them each a macro:

Sub Show()
ActiveSheet.Shapes.Range(Array("InstructionsCover")).Visible = msoFalse
End Sub

Sub Hide()
ActiveSheet.Shapes.Range(Array("InstructionsCover")).Visible = msoTrue
End Sub

I'd prefer just one button/checkbox but this will work...

Thank you both for your help - much appreciated :)
 
Last edited:
Upvote 0
Thank you, folks. I do understand most of the code which has been offered as a solution (and I thought that the benefit of these forums is to ask for those of us who have not been trained or are not as skilled as others! :unsure: ), but nothing seems to be working for me. So, I have done a workaround by having two option buttons and assigning them each a macro:

Sub Show()
ActiveSheet.Shapes.Range(Array("InstructionsCover")).Visible = msoFalse
End Sub

Sub Hide()
ActiveSheet.Shapes.Range(Array("InstructionsCover")).Visible = msoTrue
End Sub

I'd prefer just one button/checkbox but this will work...

Thank you both for your help - much appreciated :)
Two of us provided code that worked for both of us so not sure why you could not get it to work. I test all my scripts. But now your original post also involved a sheet change again script which I did not use.
 
Upvote 0
It looks like you might have a Forms check box on your sheet.
If so, following code should make the shape visible/not visible.
Change references as required. Note the Check Box Name and the reference to the cell.
You have to assign the macro to the Check Box. Cell Link in this case is D2 in Sheet1
Macro goes in a regular module.
Code:
Sub Visible_Or_Hidden()
        ActiveSheet.Shapes("InstructionsCover").Visible = IIf(Sheets("Sheet1").Range("D2").Value = True, True, False)
End Sub
 
Upvote 0
Solution
If you want to toggle visibility with a single (Forms, not ActiveX) Button, named "Button 1"
Change references as required.
Code:
Sub Visible_Or_Hidden_Button()
    ActiveSheet.Shapes("InstructionsCover").Visible = IIf(ActiveSheet.Shapes("InstructionsCover").Visible = True, False, True)
    ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = IIf(ActiveSheet.Shapes("InstructionsCover").Visible = True, "Hide", "Unhide")
End Sub
 
Upvote 0
Thank you so much, @jolivanes! Your 12:13 AM solution works perfectly!

I love Excel and am learning all the time, so I really appreciate the help and expertise available on this forum :giggle:

Thank you again. Very much.
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top