Disable Checkbox on Userform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Userform with 6 Checkboxes on it. What I want it to do is if there
are 4 worksheets in the workbook then 4 of the checkboxes would be enabled
and 2 of the checkboxes would be disabled, if there are 3 worksheets in the
workbook then 4 of the checkboxes would be enabled and 3 of the checkboxes
would be disabled, and so on, is this possible?
Thanks
 
something like this would work

Private Sub UserForm_Initialize()
wscount=activeworkbook.worksheets.count
If wscount<6 then
CheckBox6.Enabled = False
End If
If wscount<5 then
CheckBox5.Enabled = False
End If

'ADD THE REST HERE

End Sub
 
Instead of handling each Checkbox separately, you can do it in a loop
instead...

Private Sub UserForm_Initialize()
Dim X As Long
Dim WScount As Long
WScount = ActiveWorkbook.Worksheets.Count
For X = 1 To 6
Me.Controls("CheckBox" & CStr(X)).Enabled = (X <= WScount)
Next
End Sub

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top