How to cycle through a series of similar objects with a for-next loop?
I am an occasional programmer and I would like some help on a problem:
I have 20 existing object labels on an Excel 2000 worksheet. They were
initially added with no attention to their caption property. I need these
labels to contain calculated data that periodically changes. My existing
code to update these labels has 20 lines like this:
txtX1.Caption = <some calculation
txtX2.Caption = <some calculation
..
..
..
txtX20.Caption = <some calculation
I want to use something more elegant like a for-next loop, but I can't seem
to figure how to dynamically change the label object reference from txtX1 to
txtX2 to txtX3 (and so on) on each iteration of the for-next loop. If I
assemble a reference as a string variable and append the .Caption, it
generates a runtime error. What is the proper method for handling a task
like this? I have often had to handle problems like this using the above
method, but I'm sure there must be a better solution.
Regards,
Derrick.
|