ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check Boxes (https://www.excelbanter.com/excel-programming/298415-check-boxes.html)

OMG

Check Boxes
 
I've placed several check boxes in a worksheet (not on a form). What I want to do through VBA is to iterate through all the check boxes and, where the "Value" property returns True then read the caption. My problem is that I can't figure out how to iterate through the boxes efficiently. With the worksheet name of "Parameters" I've tried "Parameters.CheckBox1.Value" but I want to be able to just get a collection of all checkboxes on the page and iterate

Any ideas

Chip Pearson

Check Boxes
 
If these are checkboxes from the Forms toolbar, use code like the
following:

Dim CHK As Excel.CheckBox
For Each CHK In ActiveSheet.CheckBoxes
If CHK.Value = 1 Then
MsgBox CHK.Caption
End If
Next CHK

If these are checkboxes from the Controls toolbar, use code like
the following:

Dim Obj As OLEObject
For Each Obj In ActiveSheet.OLEObjects
If TypeOf Obj.Object Is MSForms.CheckBox Then
If Obj.Object.Value Then
MsgBox Obj.Object.Caption
End If
End If
Next Obj


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"OMG" wrote in message
...
I've placed several check boxes in a worksheet (not on a form).

What I want to do through VBA is to iterate through all the check
boxes and, where the "Value" property returns True then read the
caption. My problem is that I can't figure out how to iterate
through the boxes efficiently. With the worksheet name of
"Parameters" I've tried "Parameters.CheckBox1.Value" but I want
to be able to just get a collection of all checkboxes on the page
and iterate.

Any ideas




OMG[_2_]

Check Boxes
 
Perfect. Thanks for your help.


All times are GMT +1. The time now is 07:47 AM.

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