Userforms and looping

Stubby

Board Regular
Joined
Mar 5, 2002
Messages
188
Hi

I have a userform with 5 labels on it named Lbl1, Lbl2,Lbl,Lbl4 and Lbl5.

I need to change the Caption of each label to a value that will be gained from the spreadsheet which I know I can do with code. What i would like to know is if it is possible to loop through form control names to change the caption! i'm thinking something along the lines of

x=1

for each label in userform1
lbl&x.caption=range("a1")
x=x+1
next

any help will be much appreciated
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Something like:
Code:
for x = 1 to 5
Me.controls("lbl" & x).caption=range("a1")
next x
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top