View Full Version : Hide Unhide Picture And Cell Content Using CheckBoxes
This example will need code,There are 2 checkboxes.Can I checkbox hide/unhide the picture and the other checkbox hide/unhide the text,Can the picture be a fixed size and always insert exactly like in the attached example.
Can each checkbox say hide/unhide depending on which state the button is in
Jeff
Hi
Can VBA code be used here so that when i check either box it hides or unhides.One checkbox will say Hide Picture when visible and Unhide Picture when not visible...The other checkbox will do the same for the Text
Thanks
Jeff
Excel Fox
08-03-2013, 09:28 AM
Paste this in the respective sheet module
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Me.CheckBox1.Caption = "Unhide"
Me.Shapes("WARNING").Visible = msoFalse
Else
Me.CheckBox1.Caption = "Hide"
Me.Shapes("WARNING").Visible = msoTrue
End If
End Sub
Private Sub CheckBox2_Click()
If Me.CheckBox2.Value = True Then
Me.CheckBox2.Caption = "Unhide"
Me.Range("B2").Value = ""
Else
Me.CheckBox2.Caption = "Hide"
Me.Range("B2").Value = "WARNING DO NOT ENTER"
End If
End Sub
But curious as to why you want to do this with two checkboxes, instead of one?
Admin
08-03-2013, 10:22 AM
Hi
Not sure , but does this attachment help you ?
Excel Fox
08-03-2013, 12:34 PM
And what about the other post you posted?
http://www.excelfox.com/forum/f2/hide-unhide-picture-and-cell-content-using-checkboxes-1317/
Thank you
Could I request a change....could the code show both the Picture and Text at the same time when selected and hide both the Picture and Text at the same time when selecting to hide
The code is great and appreciated
Apologies for the posts but I keep changing my mind on what I wanted.ExcelFox example is excellent as well
Jeff
Excel Fox
08-03-2013, 01:33 PM
To do this with just one checkbox, use this. This is also in response line with the posts at http://www.excelfox.com/forum/f2/checkbox-to-hide-unhide-picture-and-text-1316/
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Me.CheckBox1.Caption = "Unhide"
Me.Shapes("WARNING").Visible = msoFalse
Me.Range("B2").Value = ""
Else
Me.CheckBox1.Caption = "Hide"
Me.Shapes("WARNING").Visible = msoTrue
Me.Range("B2").Value = "WARNING DO NOT ENTER"
End If
End Sub
Excel Fox
08-03-2013, 01:34 PM
I've added a code at http://www.excelfox.com/forum/f2/hide-unhide-picture-and-cell-content-using-checkboxes-1317/
Thank you ExcelFox....works a treat
Is there a code I can use to protect the cells involved so that the picture and Text cannot be deleted when visible
or would you recommend a another way to protect
Jeff
Admin
08-03-2013, 02:28 PM
I have just merged both the threads
Excel Fox
08-03-2013, 03:12 PM
You could protect the sheet while opening the workbook using the UserInterfaceOnly argument. And the VBA code will work as it is, and still not allow users to delete the picture or text. Of course the cells involved, and the pictures will have to have locked property.
e
Excel Fox
Would you have that code to suit the worksheet with the picture and text
Thanks
Excel Fox
08-03-2013, 03:33 PM
Just typing this on the fly... watch out for any typ0s
Sub Auto_Open()
Dim wks as worksheet
for each wks in thisworkbook.worksheets
wks.Unprotect PassWord:=""' If there's a password, use it within the double quote
wks.Protect UserInterfaceOnly:=True, Password=""' If there's a password, use it within the double quote
next wks
End Sub
Excel Fox
08-03-2013, 03:36 PM
If you were just wanting to protect that particular sheet, then use
Sub Auto_Open()
With Worksheets("Particular Sheet Name")
.Unprotect PassWord:=""' If there's a password, use it within the double quote
.Protect UserInterfaceOnly:=True, Password:=""' If there's a password, use it within the double quote
End With
End Sub
EDIT: Added a semi-colon to the argument
use the following code but get a error-expected named parameter
Sub Auto_Open()
With Worksheets("sheet1")
.Unprotect Password:="hello" ' If there's a password, use it within the double quote
.Protect UserInterfaceOnly:=True, Password="hello"' If there's a password, use it within the double quote
End With
End Sub
I fixed a typo as you suggested so the code does not give error but it still allows me to delete the cell contents and it does not ask for passwords
Thanks
Excel Fox
08-03-2013, 04:19 PM
I've made a small correction. Check my previous post.
Excel Fox
08-03-2013, 04:21 PM
The code has to be pasted in a code module, and not in the sheet module or workbook module. Also ensure that the cell you're using is locked.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.