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:
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Having a checkbox make a change to a cell will not cause a sheet change event to activate.
 
Upvote 0
That's what I wanted to do originally, but I couldn't find a formula (or work it out!). How would that look please?
 
Upvote 0
I did find this, but it doesn't work for me (does feel closer though!)...?

Private Sub CheckBox1Act()
With Worksheets("Kanban")
If (CheckBox1 = False) Then
ActiveSheet.Shapes("InstructionsCover").Visible = True
Else
If (CheckBox1 = True) Then
ActiveSheet.Shapes("InstructionsCover").Visible = False
End If
End If
End With
End Sub
 
Upvote 0
Assigning formula to checkbox hides the shape:

Sub HideSheet()
ActiveSheet.Shapes("InstructionsCover").Visible = False
End Sub

But I need to to unhide also, based on the checkbox... I did try the following, but am tying myself up in knots now!

Sub HideUnhideShape()
If (CheckBox1 = True) Then
ActiveSheet.Shapes("InstructionsCover").Visible = False
Else
If (CheckBox1 = False) Then
ActiveSheet.Shapes("InstructionsCover").Visible = True
End If
End Sub
 
Upvote 0
I think it should be more like this:
Do not use else statement.
VBA Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then Sheets(2).Range("A1").Value = "Me"
If CheckBox1.Value = False Then Sheets(2).Range("A1").Value = "You"

End Sub
 
Upvote 0
I'm sorry, I don't understand this. How does that hide my shape, "InstructionsCover"? And do I put $U$11 in the Range if I link the CheckBox, with = being "TRUE" and "FALSE"?

Apologies for my lack of understanding...
 
Upvote 0
You should not be using a sheet change again script.
Like I said in my first posting using a Checkbox to change a value in a sheet and then expecting that change to activate a script I do not believe will work.
And why not start out with something simple like if this happens have a message box popup like say hello

Then if that works proceed.
 
Upvote 0
Goes in the Sheet module.
Change references, like Sheet names etc, as required
Code:
Private Sub CheckBox1_Click()
    If Sheets("Sheet1").CheckBox1.Value = True Then
        ActiveSheet.Shapes("InstructionsCover").Visible = False
            Else
        ActiveSheet.Shapes("InstructionsCover").Visible = True
    End If
End Sub
Can be written quite a bit shorter but this is easy to understand and change.
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,133
Members
449,098
Latest member
Doanvanhieu

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