VBA / change caption of ActiveX checkboxes using a loop

PhilippeMortreux

New Member
Joined
Jan 24, 2013
Messages
3
Hello,

I am trying to change checkboxes caption name using a loop so that I don't have to change them individually.
Here is a simplified example of what want to do:

1) I save the caption names in a array
2) I run through a loop to rename each checkboxes using the names saved in the array

Sub change_Checkbox_Caption

Dim MyArray(1to3) as string
Dim IndexMyArray as integer

MyArray(1) = "YES"
MyArray(2) = "No"
MyArray(3) = "Maybe"

For indexMyArray = 1 to 3

Sheets(1).checkbox& IndexMyArray.Caption =MyArray(IndexMyArray).value

Next indexMyArray

end sub

I am really stucked, if you have a solution to suggest it would be very helpful
Thankfully
-Phil
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG24Jan25
[COLOR="Navy"]Dim[/COLOR] MyArray(1 To 3) [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] IndexMyArray [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
MyArray(1) = "YES"
MyArray(2) = "No"
MyArray(3) = "Maybe"
[COLOR="Navy"]For[/COLOR] IndexMyArray = 1 To 3
Sheets("Sheet1").OLEObjects("CheckBox" & IndexMyArray).Object.Caption = MyArray(IndexMyArray)
[COLOR="Navy"]Next[/COLOR] IndexMyArray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,721
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top