PDA

View Full Version : Solved: Making more checkboxes visible when a checkbox is checked



SallysPizza
04-01-2008, 10:16 AM
Hi!

I'm a total VBA noob, so please forgive me! I've been working on an Excel project and this is the last thing I need.

I'm trying to make several checkboxes appear only when a checkbox (i.e. Check Box 1)elsewhere on the worksheet is checked. I've tried doing this from the control menu & forms menu but any code I enter doesn't appear to be correct, so I wipe it out and start all over.

Any help would be greatly appreciated!:bow:

Bob Phillips
04-01-2008, 10:22 AM
Which CB is the driver, which get hidden/unhidden?

SallysPizza
04-01-2008, 10:26 AM
The "Full Produce" is the driver - I haven't put in the other checkboxes yet since everytime I tried I failed.

Bob Phillips
04-01-2008, 10:43 AM
This code will toggle all the check boxes 11-15 based upon Full Produce, just assign this macro to the Full Produce CheckBox.



Public Sub ToggleCheckboxes()

With ActiveSheet

.CheckBoxes("Check Box 11").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 12").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 13").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 14").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 15").Visible = .CheckBoxes("Check Box 39").Value = 1
End With

End Sub

SallysPizza
04-01-2008, 11:53 AM
Cool! That did the trick! I'm curious, when I tried changing the Checkboxes to different numbers from "Check Box 11" to "Check Box 1" I get an error? I just used Checkboxes 11-15 that were elsewhere on the sheet and it worked fine, but I was wondering what it was I did incorrectly.

Thanks VERY much!

Bob Phillips
04-01-2008, 12:16 PM
Works fine for me. Did you change it in the Names box?

SallysPizza
04-02-2008, 07:05 AM
This code will toggle all the check boxes 11-15 based upon Full Produce, just assign this macro to the Full Produce CheckBox.



Public Sub ToggleCheckboxes()

With ActiveSheet

.CheckBoxes("Check Box 11").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 12").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 13").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 14").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 15").Visible = .CheckBoxes("Check Box 39").Value = 1
End With

End Sub

What I did was add more check boxes and changed your code to this:


Public Sub ToggleCheckboxes()

With ActiveSheet

.CheckBoxes("Check Box 1").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 2").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 3").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 4").Visible = .CheckBoxes("Check Box 39").Value = 1
.CheckBoxes("Check Box 5").Visible = .CheckBoxes("Check Box 39").Value = 1
End With

End Sub
I tried it this way since check boxes 11-15 were used elsewhere. I'm just wondering why it didn't work. Again, VB is still a foreign language to me so what may be something very obvious is still a mystery to me. No matter because I just moved and renamed boxex 11-15 to where I needed them and added new ones to replace them.