Hello all,
I am currently working on a user form that shall be used to display the contents of the active row.
Thus I created a form that contains e.g. 20 Labels and 20 TextBoxes. The names of the fields are currently 'Label1', 'Label2' ... 'Label20' and 'TextBox1', 'TextBox2' ... 'TextBox20'.
The values of the Labels and Textboxes shall be set with the 'Initialize' function.
As I have 20 Labels I am currently trying to figure out the best way to set the values when the form is loaded.
Is there any chance to refer to the objects by using them with FOR ... NEXT for example like this:
FOR x = 1 to 20
MyForm.Label(x).Caption = ActiveSheet.Cells(1, x).Value
MyForm.Label(x).Text =ActiveSheet.Cells(ActiveCell.Row, x).Value
NEXT
This would be much easier than defining the values separately for each Label and TextBox.
I already tried to define a (string) variable that combines the correct object name (e.g. vLabel = "MyForm.Label" + Str(x) + ".Caption") but this does not work as this is not an object.
Could you please give me a hint ?
Many thanks in advance for your help !
Claus.
P.S.: I am pretty new to VBA, so please excuse if this is a dumb question.
Bookmarks