ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   CheckBox (https://www.excelbanter.com/excel-programming/411555-checkbox.html)

Jean

CheckBox
 
Hi
I have one UserForm1 with 14 CheckBox All are Enabled = false
I would like make part of these checkBox Enabled=True
And Show the userForm1 with all checkBox some enabled other disabled
to permit to check only some of checkboxes Enabled.

Sub Print_period()
Dim Cbk As CheckBox
Dim Count As Integer
Dim Prd As Integer
Prd = 5
Count = 0
For Each Cbk In UserForm1.checkbox '13 checkbox
Count = Count + 1
If Count < Prd Then
Cbx.Enabled = True
End If
Next

UserForm1.Show

But Something is wrong.

Thank you for your help.

Jean

Rick Rothstein \(MVP - VB\)[_2001_]

CheckBox
 
Try it like this...

Dim Count As Integer
Dim Prd As Integer
Dim Cntrl As Control
Prd = 5
Count = 0
For Each Cntrl In UserForm1.Controls
If TypeOf Cntrl Is MSForms.CheckBox Then
Count = Count + 1
If Count < Prd Then
Cntrl.Enabled = True
End If
End If
Next

UserForm1.Show


Rick



"jean" wrote in message
...
Hi
I have one UserForm1 with 14 CheckBox All are Enabled = false
I would like make part of these checkBox Enabled=True
And Show the userForm1 with all checkBox some enabled other disabled
to permit to check only some of checkboxes Enabled.

Sub Print_period()
Dim Cbk As CheckBox
Dim Count As Integer
Dim Prd As Integer
Prd = 5
Count = 0
For Each Cbk In UserForm1.checkbox '13 checkbox
Count = Count + 1
If Count < Prd Then
Cbx.Enabled = True
End If
Next

UserForm1.Show

But Something is wrong.

Thank you for your help.

Jean



Bob Phillips

CheckBox
 
I wouldn't use Count as a variable name, and I would also refer to the
controls by name, otherwise they get referenced in the order that you create
them, which might not be what is wanted.

So assuming you name them all logically, I have left as the defaults here,
then

Sub Print_period()
Dim Cnt As Long
Dim Prd As Long
Prd = 5
Cnt = 1
Do While Cnt < Prd

Me.Controls("CheckBox" & Cnt).Enabled = True
Cnt = Cnt + 1
Loop
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"jean" wrote in message
...
Hi
I have one UserForm1 with 14 CheckBox All are Enabled = false
I would like make part of these checkBox Enabled=True
And Show the userForm1 with all checkBox some enabled other disabled
to permit to check only some of checkboxes Enabled.

Sub Print_period()
Dim Cbk As CheckBox
Dim Count As Integer
Dim Prd As Integer
Prd = 5
Count = 0
For Each Cbk In UserForm1.checkbox '13 checkbox
Count = Count + 1
If Count < Prd Then
Cbx.Enabled = True
End If
Next

UserForm1.Show

But Something is wrong.

Thank you for your help.

Jean





All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com