View Full Version : Solved: Need help with Loop routine to enable 20+ checkboxes
cgannm
06-10-2008, 12:34 PM
Hi. I recently found this code that enables checkboxes and works well. I would like to expand code to enable 20+ checkboxes and need help with loop routine. Can you help?
Private Sub Chk1_Click()
If Chk1 = True Then
MsgBox "test."
Chk2.Enabled = True
Chk3.Enabled = True
Chk4.Enabled = True
ElseIf Chk1 = False Then
Chk2.Enabled = False
Chk3.Enabled = False
Chk4.Enabled = False
End If
End Sub
thanks,
anna
Bob Phillips
06-10-2008, 12:47 PM
Private Sub Chk1_Click()
Dim i As Long
For i = 2 To 20
Controls("Chk" & i).Enabled = Chk1.Value
Next i
End Sub
cgannm
06-10-2008, 01:45 PM
Hi, thanks for helping getting: sub or function not defined on "Controls".
Bob Phillips
06-10-2008, 02:06 PM
This is a userform code is it not?
cgannm
06-10-2008, 02:39 PM
Yes. I am using checkboxes from Control box and applied to Sheet1. Below is where obtained code.
http://www.vbaexpress.com/forum/showthread.php?t=13195
Bob Phillips
06-10-2008, 03:01 PM
Private Sub Chk1_Click()
Dim i As Long
For i = 2 To 20
OLEObjects("Chk" & i).Object.Enabled = Chk1.Value
Next i
End Sub
cgannm
06-11-2008, 09:51 AM
Hi,Xid, this works! Still have much to learn, your time and efforts are appreciated.
Anna
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.