Clear All Checkboxes?

G

Guest

I'm developing a fairly complex Userform with 8 checkboxes. Is there a way to
control all boxes with one command. Say for example the end user selects 6 of
the 8 boxes, then clicks run and then excel does its thing. My question is,
is there anyway to clear all the checkboxes with one line, instead of
checkbox1.value = false, checkbox2.value = false, etc...? Or another example
would be if none of the checkboxes are selected then my msgbox would appear,
but be able to do this in one line. I just want to simplfy the code from 8
lines to 1 line. Thanks.
 
S

Sharad Naik

Add a Frame in the userform and move all the checkboxes in to that frame.
If userform name is UF1 and Fram name is Frm1 Then
You can do:

Dim chBx
For each chBx in Frm1.Controls
chBx.Value = False
Next

Sharad
 
T

Tom Ogilvy

for each ctrl in userform1.controls
if typeof ctrl is MsForms.checkbox then
ctrl.Value = False
end if
Next

or

for i = 1 to 8
if userform1.Controls('checkbox" & i).Value = False
Next

there is no Checkboxes.Clear command.
 
C

Claud Balls

Here is a snip-it from one of my macros to clear text boxes, maybe you
can alter it to work for you.

For Each txtcontrol In Controls
If Left(txtcontrol.Name, 2) = "tx" Then txtcontrol.Text = ""
Next
 

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

Top