locked
define a name of a commandbutton with a variable in it RRS feed

  • Question

  • I would like to know how I can set properties of a commandbutton in a userform with defining it's name not by typing 'commandbutton1' but by typing 'commandbutton + number' as name with number = 1, using it like that i should be able to make a for number = 1 to 10 ... next loop and set properties to each commandbutton with the name commandbutton1, commandbutton2, ..., commandbutton10.


    Wednesday, March 20, 2013 4:22 PM

All replies

  • Like this:

    Dim i As Integer
    For i = 1 To 10
    Me.Controls("CommandButton" & i).Caption = "I'm Button #" & i
    Next i

    Wednesday, March 20, 2013 5:18 PM
  • thanks, it works perfect!
    Wednesday, March 20, 2013 7:22 PM