ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   [HELP] How to use command buttons in cycles (https://www.excelbanter.com/excel-programming/330646-%5Bhelp%5D-how-use-command-buttons-cycles.html)

C.F.

[HELP] How to use command buttons in cycles
 
i've a problem in VBE (visual basic excel).

i've created a user form with more than 30 command buttons.
for each command button i've to change its field ".caption"
capturing a specific cell content.

for example:

in cells A1:A30 i've 30 different names. i've to associate :

range("A1").value to commandbutton1.caption
......
.....
range("A30").value to commandbutton30.caption

i would like to do it with a cycle (for..next, or smthg
similar).

the code i would like to writew down is:

for every commandbutton in userform1 do
commandbutton.caption=range("A1").value

the problem is i've to specify the number of command button
i'm workin' with

so the extended code i actually use is :

with userform1
commandbutton1.caption=range("A1").value
......
commandbutton30.caption=range("A30").value


i would like to substitute these 30 lines of code with a
single cycle/loop.

thanks in advance .






Tom Ogilvy

[HELP] How to use command buttons in cycles
 
for i = 1 to 30
userform1.Controls("CommandButton" & i).Caption = _
Range("A" & i).Value
Next i

--
Regards,
Tom Ogilvy


"C.F." wrote in message
...
i've a problem in VBE (visual basic excel).

i've created a user form with more than 30 command buttons.
for each command button i've to change its field ".caption"
capturing a specific cell content.

for example:

in cells A1:A30 i've 30 different names. i've to associate :

range("A1").value to commandbutton1.caption
.....
....
range("A30").value to commandbutton30.caption

i would like to do it with a cycle (for..next, or smthg
similar).

the code i would like to writew down is:

for every commandbutton in userform1 do
commandbutton.caption=range("A1").value

the problem is i've to specify the number of command button
i'm workin' with

so the extended code i actually use is :

with userform1
commandbutton1.caption=range("A1").value
.....
commandbutton30.caption=range("A30").value


i would like to substitute these 30 lines of code with a
single cycle/loop.

thanks in advance .








C.F.

[HELP] How to use command buttons in cycles
 
for i = 1 to 30
userform1.Controls("CommandButton" & i).Caption = _
Range("A" & i).Value
Next i



really thanks.

i've another quick question:

if i would declare an array of command buttons how i should
do that??

again thank for your answer you've solved me a lot of
problems!

Tom Ogilvy

[HELP] How to use command buttons in cycles
 
Something like:

Dim v as MSForms.Commandbutton
redim v(1 to 30)
for i = 1 to 30
set v(i) = Userform1.Controls("Commandbutton" & i)
Next

--
Regards,
Tom Ogilvy


"C.F." wrote in message
...
for i = 1 to 30
userform1.Controls("CommandButton" & i).Caption = _
Range("A" & i).Value
Next i



really thanks.

i've another quick question:

if i would declare an array of command buttons how i should
do that??

again thank for your answer you've solved me a lot of
problems!





All times are GMT +1. The time now is 02:45 PM.

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