Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Loop for checkboxes

Control Checkboxes. Matt
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Checkboxes Randy L Excel Discussion (Misc queries) 3 February 22nd 06 08:09 PM
ADO and Checkboxes Merkling, Steven Excel Programming 1 December 18th 03 12:08 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM
For each...loop for checkboxes Steven Cheng[_3_] Excel Programming 4 August 6th 03 07:04 AM


All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"