View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
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