Dynamically Adding Labels to User Form = Blank UserForm
A few things:
- You need to show your UserForm as
vbModeless
- else the code stops onUserForm2.Show
- You are creating an object called
Label
then usingWith
ontheLabel
You will then need to increment the position of your three labels to avoid overlap (which I have done using
Top
).Sub addLabel() UserForm2.Show vbModeless Dim theLabel As Object Dim labelCounter As Long For labelCounter = 1 To 3 Set theLabel = UserForm2.Controls.Add("Forms.Label.1", "Test" & labelCounter, True) With theLabel .Caption = "Test" & labelCounter .Left = 10 .Width = 50 .Top = 10 * labelCounter End With Next End Sub