Home > OS >  Commandbutton with dynamic numbers
Commandbutton with dynamic numbers

Time:11-12

How would I go about creating dynamic Commandbutton references? i.e. change

MANAGER.CommandButton01.Caption = Sheets("DATA").Range("C" & Rows)

(which works perfectly, but only on one button of course) - to, for example:

MANAGER.CommandButton("0" & (Rows - 2)).Caption = Sheets("DATA").Range("C" & Rows)

(this code doesn't work, but it's what I've been playing around with)

So that the Commandbutton's caption is updated depending on which line of code was edited using the MANAGER Userform.

Rows can be double digits, so the "0" will have to be replaced with just Rows after Row 11, but I haven't gotten to that stage yet.

CodePudding user response:

I think what you are looking for is the reference to the Controls of the userform.

MANAGER.Controls("CommandButton" & Format(Rows-2,"00")).Caption = Sheets("DATA").Range("C" & Rows)
  • Related