I am trying to use a index to cycle through multiple command buttons inside a user form.

kerrywayne

New Member
Joined
Jul 21, 2023
Messages
9
Office Version
  1. 2003 or older
Platform
  1. Windows
I am trying to use a index to cycle through multiple command buttons inside a user form. I want to be able to refer to each button as "CommandButton" & number as the button names. The button .captions are stored in an array and I want to use a For Next loop the assight the captions to the command buttons. Is this doable without getting into ole coding? I have 88 command buttons.

I found the below code with Google search..

Dim bt As MSForms.CommandButton
Set bt = ActiveSheet.OLEObjects("Bridge_cmdbutton" & Number).Object
bt.Caption = "Some Descriptive Text"

At Least 2 problems: 1) my command buttons are not OLEObjects, 2) I am not inside a worksheet.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I am trying to use a index to cycle through multiple command buttons inside a user form. I want to be able to refer to each button as "CommandButton" & number as the button names. The button .captions are stored in an array and I want to use a For Next loop the assight the captions to the command buttons. Is this doable without getting into ole coding? I have 88 command buttons.

I found the below code with Google search..

Dim bt As MSForms.CommandButton
Set bt = ActiveSheet.OLEObjects("Bridge_cmdbutton" & Number).Object
bt.Caption = "Some Descriptive Text"

At Least 2 problems: 1) my command buttons are not OLEObjects, 2) I am not inside a worksheet.
I tried the below as well.

Number = 0
commandbuttonname = "CommandButton" & Number
Comandbuttonname.Caption = "adfasdf"
 
Upvote 0
You can reference and update multiple CommandButton properties (eg Caption) with syntax like [Me.Controls("CommandButton" & Index).Caption].
 
Upvote 1
Solution
Thank You Sir. I notice that both of the below work.

1691972496358.png


and

1691972703884.png


Those two letters "Me"....I'll have to research what that is all about.

Thanks Again,

Kerry
 

Attachments

  • 1691971741641.png
    1691971741641.png
    10.7 KB · Views: 2
  • 1691971917689.png
    1691971917689.png
    10.7 KB · Views: 2
  • 1691971954374.png
    1691971954374.png
    7 KB · Views: 2
  • 1691972057309.png
    1691972057309.png
    7 KB · Views: 2
  • 1691972067881.png
    1691972067881.png
    9.4 KB · Views: 2
  • 1691972334985.png
    1691972334985.png
    7.8 KB · Views: 1
  • 1691972585515.png
    1691972585515.png
    8.5 KB · Views: 4
  • 1691972692105.png
    1691972692105.png
    8.5 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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