ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA array of checkboxes (https://www.excelbanter.com/excel-programming/308796-excel-vba-array-checkboxes.html)

Eliezer

Excel VBA array of checkboxes
 
I have 44 checkboxes on a VBA Excel form that I dragged
there from the Toolbox. I named them all rep1_cb,
rep2_cb, rep3_cb, ... rep44_cb.

I want to add a button to the forum to un/check all
checkboxes within this "group". Is there some way to
store them all within an array - or create some sort of
loop without having to individually change the value of
each and every one of them?

Thanks!
Eliezer

Charles Maxson

Excel VBA array of checkboxes
 
Eliezer

Here's a simple for each loop that looks at the names of all controls and
reverses the values for the ones you designated as "rep" control check
boxes:


Private Sub cmdCheckBoxes_Click()
Dim ctrl As Control

For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "rep" Then
ctrl.Value = Not ctrl.Value
End If
Next

End Sub


--
Charles
www.officezealot.com


"Eliezer" wrote in message
...
I have 44 checkboxes on a VBA Excel form that I dragged
there from the Toolbox. I named them all rep1_cb,
rep2_cb, rep3_cb, ... rep44_cb.

I want to add a button to the forum to un/check all
checkboxes within this "group". Is there some way to
store them all within an array - or create some sort of
loop without having to individually change the value of
each and every one of them?

Thanks!
Eliezer




Eliezer

Excel VBA array of checkboxes
 
Charles,

Excellent! Thanks!
Eliezer


-----Original Message-----
Eliezer

Here's a simple for each loop that looks at the names of

all controls and
reverses the values for the ones you designated as "rep"

control check
boxes:


Private Sub cmdCheckBoxes_Click()
Dim ctrl As Control

For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "rep" Then
ctrl.Value = Not ctrl.Value
End If
Next

End Sub


--
Charles
www.officezealot.com


"Eliezer" wrote in

message
...
I have 44 checkboxes on a VBA Excel form that I dragged
there from the Toolbox. I named them all rep1_cb,
rep2_cb, rep3_cb, ... rep44_cb.

I want to add a button to the forum to un/check all
checkboxes within this "group". Is there some way to
store them all within an array - or create some sort of
loop without having to individually change the value of
each and every one of them?

Thanks!
Eliezer



.



All times are GMT +1. The time now is 09:19 PM.

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