Dynamic Label
Jean
-
safoufa -
safoufa -
Hello everyone,
Here I am creating a small program in Excel VBA with userforms,
I have a ListBox that is filled based on what the user enters in a TextBox. For example, if the user enters the number 3, the ListBox displays D1, D2, D3. When I click on D1, D2, or D3, another userform opens. So far, I have no problem, it works! But now I would like that when I close the second userform, it displays the result in a LabelBox on userform1. So to summarize, it is about automatic label creation, I imagine I need to use a variable but I don't see how to create the labels (without using hide/show), if anyone can help me!
Thank you for your help!!
Jean
Here I am creating a small program in Excel VBA with userforms,
I have a ListBox that is filled based on what the user enters in a TextBox. For example, if the user enters the number 3, the ListBox displays D1, D2, D3. When I click on D1, D2, or D3, another userform opens. So far, I have no problem, it works! But now I would like that when I close the second userform, it displays the result in a LabelBox on userform1. So to summarize, it is about automatic label creation, I imagine I need to use a variable but I don't see how to create the labels (without using hide/show), if anyone can help me!
Thank you for your help!!
Jean
2 answers
Here is how to create a label in VBA
Set label_dyna = Controls.Add("forms.label.1", "label name" & a, Visible = True) ' automatic creation of the label named label name
label_dyna.top = 50 ' label displayed at 50 pixels in the height of the user form
label_dyna.left = 200 ' label to display 200 pixels to the left
label_dyna.caption = "desired value"
Set label_dyna = Controls.Add("forms.label.1", "label name" & a, Visible = True) ' automatic creation of the label named label name
label_dyna.top = 50 ' label displayed at 50 pixels in the height of the user form
label_dyna.left = 200 ' label to display 200 pixels to the left
label_dyna.caption = "desired value"