Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commandbutton with dynamic numbers

Tags:

excel

vba

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.

like image 628
Martin Avatar asked Jun 23 '26 01:06

Martin


1 Answers

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)
like image 181
Aldert Avatar answered Jun 24 '26 18:06

Aldert