PDA

View Full Version : Solved: user form control problem - using names in loop



bodhi
12-14-2005, 07:22 PM
Hi everyone,

I do not know if what i am trying to do is possible but if it is, i am sure there is a very simple answer out there. Here's what i want to do:

I have created a user form and added several command buttons to it at design time. Let's say their names are cmdBtn1, cmdBtn2, ... , cmdBtn9.

I want to be able to use the names in a loop to assign a caption to the relative command button.

eg. cmdBtn(count).caption = range("A" & count).value

is there any way to concatenate the first part of the name "cmdBtn" with a variable integer "count" and use it in the form above? http://vbaexpress.com/forum/images/smilies/102.gif

maybe there is a simpler way around this...????

http://vbaexpress.com/forum/images/smilies/think.gif

matthewspatrick
12-14-2005, 07:25 PM
Something like this, perhaps?

For Counter = 1 To 9
Me.Controls("cmdBtn" & Counter).Caption = Range("A" & Counter)
Next

bodhi
12-14-2005, 07:34 PM
matthewspatrick,

thanks for that...works perfectly...just what i was after.
http://vbaexpress.com/forum/images/smilies/023.gif

matthewspatrick
12-14-2005, 07:35 PM
Glad to be of service :cloud9: