ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   excel VBA set array controls (https://www.excelbanter.com/excel-programming/302920-excel-vba-set-array-controls.html)

Jason[_31_]

excel VBA set array controls
 
I need to address with a variable a large array of User Form Command Buttons

Dim Mybutton(5) As CommandButton

Set Mybutton(1) = CommandButton1
Set Mybutton(2) = CommandButton2
Set Mybutton(3) = CommandButton3
Set Mybutton(4) = CommandButton4
Set Mybutton(5) = CommandButton5
and so on........

so later I can use Mybutton(x).caption = "whatever"

Surly there is a way to set the array with something like.

for x = 1 to 100
Set Mybutton(x)= CommandButton & (x)
next x



Rob Bovey

excel VBA set array controls
 
Hi Jason,

How about this:

for x = 1 to 100
Set Mybutton(x)= Controls("CommandButton" & x)
next x

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Jason" wrote in message
...
I need to address with a variable a large array of User Form Command

Buttons

Dim Mybutton(5) As CommandButton

Set Mybutton(1) = CommandButton1
Set Mybutton(2) = CommandButton2
Set Mybutton(3) = CommandButton3
Set Mybutton(4) = CommandButton4
Set Mybutton(5) = CommandButton5
and so on........

so later I can use Mybutton(x).caption = "whatever"

Surly there is a way to set the array with something like.

for x = 1 to 100
Set Mybutton(x)= CommandButton & (x)
next x






All times are GMT +1. The time now is 08:01 AM.

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