Calling a checkbox control with VB

L

lee.marshall

Hi

Is there a way I can reference a checkbox item that I can manipulate
in VBA.

For instance...

I have a series of check boxes that I would like to change the
properties of with a loop

So my checkboxes are called:

CheckBox1
CheckBox2
CheckBox3
etc

and I want to be able to reference them like so:
For i = 1 to 20
"CheckBox" & i.Value = true
next i


Any ideas?
 
B

Bob Phillips

By the format of the name, I assume that they are control toolbox
checkboxes.

Dim oOLE As Object

For Each oOLE In ActiveSheet.OLEObjects
If TypeName(oOLE.Object) = "CheckBox" Then
oOLE.Object.Value = True
End If
Next oOLE


--
---
HTH

Bob

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

lee.marshall

Hi Bob

That is cool!

Just one other question. If I have a row of say 5 check boxes which I
have name CheckBox1a through CheckBox1e and then a new set of
checkboxes named CheckBox2a through CheckBox2e then
CheckBox3a through CheckBox3e

How can I reference them in such a way that if I select 'CheckBox2c'
then CheckBox2a, CheckBox2b, CheckBox2d and CheckBox2a become
unchecked.

Does that make sense?

Cheers!
 
B

Bob Phillips

Perfect sense Lee.

One question. How are you going to set these checkboxes? Will it be code in
each of the checkbox click events to set all of the others, or do you want
to loop through all checkboxes, and set the others in the group? If the
latter, you realise that if say 2a and 2b is set, it will always work on the
2a, unsettling 2b always.

--
---
HTH

Bob

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

lee.marshall

Hi Bob

Yes I have just been tinkering with method 2 of yours, and yes you are
right, it is very unsettling

Cheers
 
B

Bob Phillips

So what's the answer.

--
---
HTH

Bob

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

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