Hide Checkbox based on Cell Value

bakunawa

New Member
Joined
Jan 27, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone!

I'm working on an Excel Sheet where checkboxes need to be hidden based on (L29) Cell Value (Yes/No)

I've done some digging and came up with this:

1643293992186.png


However, when I run change the Value in Cell L29, i get this error:

1643294034044.png


I thought that maybe I have my checkbox name wrong, so I selected the Checkbox and Viewed it's code and got this:

1643294076375.png


Which makes me think that I did use the correct Checkbox name (CheckBox59), but still getting an error. Can anyone enlighten me and help me out? Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I thought that maybe I have my checkbox name wrong, so I selected the Checkbox and Viewed it's code and got this:

Looks like it is an ActiveX control and not a Form control

Instead of

VBA Code:
ActiveSheet.Shapes("CheckBox59").Visible= False

use

VBA Code:
CheckBox59.Visible= False
 
Upvote 0
Looks like it is an ActiveX control and not a Form control

Instead of

VBA Code:
ActiveSheet.Shapes("CheckBox59").Visible= False

use

VBA Code:
CheckBox59.Visible= False

Thanks for the quick answer! Yes, im using Form Control checkboxes. I tried what you said above and did this:
1643294762674.png


but whenever I change L29's value, I get this error message:

1643294795784.png
 
Upvote 0
Are you sure it is a form control? If it is, then

VBA Code:
ActiveSheet.Shapes("CheckBox59").Visible = False

should work unless the name is is different? Something like

VBA Code:
ActiveSheet.Shapes("Check Box 59").Visible = False

You can check the name in the Name Box as shown below

1643295098262.png
 
Upvote 0
Are you sure it is a form control? If it is, then

VBA Code:
ActiveSheet.Shapes("CheckBox59").Visible = False

should work unless the name is is different? Something like

VBA Code:
ActiveSheet.Shapes("Check Box 59").Visible = False

You can check the name in the Name Box as shown below

View attachment 56270
Renaming them did the trick! Thank you so much!
 
Upvote 0
Are you sure it is a form control? If it is, then

VBA Code:
ActiveSheet.Shapes("CheckBox59").Visible = False

should work unless the name is is different? Something like

VBA Code:
ActiveSheet.Shapes("Check Box 59").Visible = False

You can check the name in the Name Box as shown below

View attachment 56270
Follow up question!

I need to hide/unhide a different set of checkboxes based on a different (K26) cell Value. Do i just add the formulas below the End Sub like so?

VBA Code:
 Private Sub Worksheet_Change(ByVal Target As Range)

 If ActiveSheet.Range("k29").Value = "Yes" Then
ActiveSheet.Shapes("CheckBox1").Visible = True
ActiveSheet.Shapes("CheckBox2").Visible = True
Else
ActiveSheet.Shapes("CheckBox1").Visible = False
ActiveSheet.Shapes("CheckBox2").Visible = False
End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
 If ActiveSheet.Range("k26").Value = "Yes" Then
 ActiveSheet.Shapes("CheckBox3").Visible = True
 Else
 ActiveSheet.Shapes("CheckBox3").Visible = False
End Sub
 
Upvote 0
Follow up question!

I need to hide/unhide a different set of checkboxes based on a different (K26) cell Value. Do i just add the formulas below the End Sub like so?

VBA Code:
 Private Sub Worksheet_Change(ByVal Target As Range)

 If ActiveSheet.Range("k29").Value = "Yes" Then
ActiveSheet.Shapes("CheckBox1").Visible = True
ActiveSheet.Shapes("CheckBox2").Visible = True
Else
ActiveSheet.Shapes("CheckBox1").Visible = False
ActiveSheet.Shapes("CheckBox2").Visible = False
End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
 If ActiveSheet.Range("k26").Value = "Yes" Then
 ActiveSheet.Shapes("CheckBox3").Visible = True
 Else
 ActiveSheet.Shapes("CheckBox3").Visible = False
End Sub

No no. You can use the same proc.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveSheet.Range("k29").Value = "Yes" Then
        ActiveSheet.Shapes("CheckBox1").Visible = True
        ActiveSheet.Shapes("CheckBox2").Visible = True
    Else
        ActiveSheet.Shapes("CheckBox1").Visible = False
        ActiveSheet.Shapes("CheckBox2").Visible = False
    End If
   
    If ActiveSheet.Range("k26").Value = "Yes" Then
        ActiveSheet.Shapes("CheckBox3").Visible = True
    Else
        ActiveSheet.Shapes("CheckBox3").Visible = False
    End If
End Sub
 
Upvote 0
Solution
Follow up question to this - I am using the code above, but in my case the cell "k29" (the one being checked for a value of "yes") is a formula that is determined to output "yes" or "no" based on checkboxes that are selected on another sheet. The issue is that when I make the inputs on the other sheet, and the value of my cell "k29" on the other sheet changes to yes, the checkbox does not automatically hide. It looks like it only works if I re-paste the formula so that the change happens while the sheet with the checkbox that is to be hidden is active.

Is there a way to make it so that the checkbox will hide or unhide even if the reference cell is based on changes that are made to another sheet?
 
Upvote 0
Sorry, I am a very beginner. It looks like the checkbox updates when any change is made on the worksheet. I guess this is because we are under the Worksheet Change event. How can I rewrite the code such that it automatically updates every time I go back to the worksheet from the other worksheet where the changes are made?
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,688
Members
449,117
Latest member
Aaagu

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