Hiding Picture & Sheet from checkbox

NiallCollins

New Member
Joined
Mar 31, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Good Morning All,

I need to hide a sheet & an image when a checkbox is unchecked. Its so when the checkbox is unchecked, The image, which is a shortcut to the page when clicked, is no longer visible. I can get either or working but need to know how to do both together.

Thanks in advance
Niall
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
By "page" do you mean "sheet" ?

Is the checkbox active-x ?

What is the shortcut ?
- is it a hyperlink ?
- is it an assigned macro ? (please post the code )
- or something else (please explain)

How many similar checkboxes are there ?
 
Upvote 0
I've been using form control Checkboxes and the image is a macro shortcut to the correct sheet. Self teaching myself this but tried both active x and form control, i can get the image to hide on form control and the sheet to hide on Active X but struggling with getting the other action to work together with it. There will be 16 Checkboxes and associated sheets together.

Happy to switch around to active x or form control, whichever works best.

Here is an example of the shortcut image macro, (ADP is my image file name)

VBA Code:
Sub ADP_Click()
    Sheets("Automatic Doors").Select
End Sub
 
Upvote 0
I will post code later today for you
Are you happy to rename your picture the same as the sheet name and also make checkbox caption the same as the sheet name?
Can then call the same macro for EVERY checkbox rather than specifying each shape and sheet separately

thanks
 
Upvote 0
Here you go
Put code in a module like Module 1
Test it to see if it does what you want and then I'll explain the code in detail for you

VBA Code:
Private Sub HideSheetAndImage(aCheckBox As Shape)
    Dim BoxChecked As Boolean, BoxCaption As String, BoxImage As Shape, BoxSheet As Worksheet
    With aCheckBox.OLEFormat.Object
        BoxChecked = (.Value = 1)
        BoxCaption = .Caption
    End With
    Set BoxImage = ActiveSheet.Shapes(BoxCaption)
    Set BoxSheet = Sheets(BoxCaption)
   
    BoxImage.Visible = Not BoxChecked
    BoxSheet.Visible = Not BoxChecked
End Sub

And you also need ONE of these for EVERY checkbox in the same module
VBA Code:
Sub CheckBox1_Click()
    Call HideSheetAndImage(ActiveSheet.Shapes(Application.Caller))
End Sub

So using your earlier example
1 the sheet is named Automatic Doors
2 the image is also named Automatic Doors
3 the caption for its check box is Automatic Doors

Automatic Doors.jpg
 
Upvote 0
I should have mentioned in post#6 that the code is written for Form Control Chechboxes
 
Upvote 0
Thank you so much. It works a treat but only one thing, Its the wrong way round. The image and sheet are showing when the checkbox is unchecked
 
Upvote 0
In that case you want this,
Have also reduced the number of lines

VBA Code:
Private Sub HideSheetAndImage(aCheckBox As Shape)
    Dim BoxChecked As Boolean, BoxCaption As String
    With aCheckBox.OLEFormat.Object
        BoxChecked = (.Value = 1)
        BoxCaption = .Caption
    End With
    ActiveSheet.Shapes(BoxCaption).Visible = BoxChecked
    Sheets(BoxCaption).Visible = BoxChecked
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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