Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Is it possible in VBA to do a typical loop? Such as this. Basically I want checkboxes 2-5 to be invisible if checkbox 1 is not checked. I've found that it will not allow me to put in the "x + 1". Thanks. Matt
const x = If checkbox1.value = fals do while x < checkbox(x).visible = fals x + loo end if |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
What sort of checkboxes, userform, forms toolbar, or control toolbar?
-- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Matt" wrote in message ... Is it possible in VBA to do a typical loop? Such as this. Basically I want checkboxes 2-5 to be invisible if checkbox 1 is not checked. I've found that it will not allow me to put in the "x + 1". Thanks. Matt. const x = 2 If checkbox1.value = false do while x < 5 checkbox(x).visible = false x + 1 loop end if |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Control Checkboxes. Matt
|
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
I'd like to know how to do this on a Userform.
-----Original Message----- What sort of checkboxes, userform, forms toolbar, or control toolbar? -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Matt" wrote in message ... Is it possible in VBA to do a typical loop? Such as this. Basically I want checkboxes 2-5 to be invisible if checkbox 1 is not checked. I've found that it will not allow me to put in the "x + 1". Thanks. Matt. const x = 2 If checkbox1.value = false do while x < 5 checkbox(x).visible = false x + 1 loop end if . |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Hi Matt,
Something like this should work: Private Sub CheckBox1_Click() Dim ole As OLEObject For Each ole In OLEObjects If TypeOf ole.Object Is MSForms.CheckBox Then If ole.Name < "CheckBox1" Then ole.Visible = CheckBox1.Value End If End If Next ole End Sub It loops through all OLEObjects, and if the current OLEObject in the loop is a CheckBox, it will set its Visible property according to the value of CheckBox1. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Matt wrote: Control Checkboxes. Matt |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Jake, thanks. This helps, but I forgot to mention that I have other control checkboxes on the worksheet that I don't want to be dependent on checkbox1. I just want a selection dependent on the first checkbox. Any ideas? Thanks. Matt
|
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Matt,
If your CheckBoxes are named "CheckBox1", "CheckBox2", and so on, you can use this: Private Sub CheckBox1_Click() Dim ole As OLEObject Dim nChkNum As Integer For Each ole In OLEObjects If TypeOf ole.Object Is MSForms.CheckBox Then nChkNum = CInt(Mid$(ole.Name, Len("CheckBox") + 1)) If nChkNum = 2 And nChkNum <= 5 Then ole.Visible = CheckBox1.Value End If End If Next ole End Sub If not, you will have to change the If statement to something like this: If ole.Name="Mychk2" Or ole.Name="check3" Or ole.Name="checkbox04" Then -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Matt wrote: Jake, thanks. This helps, but I forgot to mention that I have other control checkboxes on the worksheet that I don't want to be dependent on checkbox1. I just want a selection dependent on the first checkbox. Any ideas? Thanks. Matt |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Matt,
Please try to keep a question in the same thread. I didn't see your thread on this subject posted 1 1/2 hours prior to this one (and those answering your other thread probably didn't see this one), so a lot of duplicated work resulted. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Matt wrote: Is it possible in VBA to do a typical loop? Such as this. Basically I want checkboxes 2-5 to be invisible if checkbox 1 is not checked. I've found that it will not allow me to put in the "x + 1". Thanks. Matt. const x = 2 If checkbox1.value = false do while x < 5 checkbox(x).visible = false x + 1 loop end if |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop for checkboxes
Rob,
This is the sort of thing that you want Dim ctl As MSForms.Control For Each ctl In Me.Controls If TypeName(ctl) = "CheckBox" Then If ctl.Value < True Then ctl.Visible = False End If End If Next ctl -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Rob" wrote in message ... I'd like to know how to do this on a Userform. -----Original Message----- What sort of checkboxes, userform, forms toolbar, or control toolbar? -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Matt" wrote in message ... Is it possible in VBA to do a typical loop? Such as this. Basically I want checkboxes 2-5 to be invisible if checkbox 1 is not checked. I've found that it will not allow me to put in the "x + 1". Thanks. Matt. const x = 2 If checkbox1.value = false do while x < 5 checkbox(x).visible = false x + 1 loop end if . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
Checkboxes | Excel Discussion (Misc queries) | |||
ADO and Checkboxes | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming | |||
For each...loop for checkboxes | Excel Programming |