Label is one of the UserForm control. You can select and drag Label on the UserForm. Label is used to display show text or information. It can be title, caption, etc. It can be used on the UserForm. You can see how it works and more details about Userform Label Control on the UserForm in the following chapter.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

VBA ActiveX Label_Control on the UserForm

Please find more details about VBA ActiveX Label Control on the UserForm.

  1. Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
  2. Go To Insert Menu, Click UserForm. Please find the screenshot for the same.
  3. Drag the label control on the Userform from the Toolbox. Please find the screenshot for the same.
  4. Click on the properties.
  5. On the left side find ‘Caption’ from the available properties.
  6. On the right side mention as ‘Welcome!’. Please find the below screen shot for the same.
  7. Like this you can add number of Label controls on the UserForm according to your requirement.

Add dynamic Label_Control on the UserForm using VBA

Please find the following steps and example code, it will show you how to add dynamic Label control on the userform.

  1. Add Label and CommandButton on the userform from the toolbox.
  2. Right click on the CommandButton, click properties
  3. Change the CommandButton caption to ‘Create_Label ’
  4. Double click on the CommandButton
  5. Now, it shows the following code.
  6. Private Sub CommandButton1_Click()
    End Sub
  7. Call the below procedure named ‘Add_Dynamic_Label ’ and find the below procedure to run.
  8. Private Sub CommandButton1_Click()
    Call Add_Dynamic_Label 
    End Sub

    Procedure to call in the CommandButton:

    Sub Add_Dynamic_Label()
    'Add Dynamic Label and assign it to object 'Lbl'
    Set lbl = UserForm2.Controls.Add("Forms.Label.1")
    'Assign Label Name
    lbl.Caption = "Dynamic Label"
    'Label Border Style
    lbl.BorderStyle = 2
    'Label Position
    lbl.Left = 10
    lbl.Top = 10
    End Sub
  9. Now, click F5 to run the macro, click ‘Create_Label ’ button to see the result.
  10. You can see the created dynamic Label which is shown in the following screen shot.
  11. output:

    Delete Label_Control on the UserForm using VBA

    Please find the below code, it will show you how to delete or remove the control on the UserForm. In the below example, its deleting the Label named ‘New Label’ which is on the UserForm named ‘UserForm4’. We can use Remove method to delete the controls which are created during run time. Controls which are created during design time cannot be deleted using this method. Please find the below example and screen shots for better understand.
    Code 1: Adding control During Run Time

    Private Sub CommandButton1_Click()
    'We can use Add method to add the new controls on run time
    Set lblBtn = Me.Controls.Add("Forms.Label.1")
    With lblBtn
    .Top = 20
    .Left = 20
    .Caption = "New Label"
    .Name = "lblNew1"
    End With
    MsgBox "New Label Added"
    End Sub

    lease find the below screen shot for your reference for the above macro and its output.
    When we click on Add Command Button:

    Code 1: Deleting or Removing label_control which is created during run time.

    Private Sub CommandButton2_Click()
    'We can use Remove method to delete the controls which are created during run time
    'Note: Controls which are created on design time cannot be deleted using this method
    Me.Controls.Remove ("lblNew1")
    MsgBox "New Label Deleted"
    End Sub

    Please find the below screen shot for your reference for the above macro and its output.
    When we click on Delete Command Button:


Related pages

sql ddl and dml commandsexcel offset function examplesexcel 2010 vba editorvbscript check file existsvba adodb.commandvba last row in rangevba special charactersexcel function in vbamatch function excel 2007excel reporting dashboarddaily task tracker on excel formattask excel templatehow to write macros in excel 2007excel vba sortproject status dashboard template powerpointexcel vlookup isnaformulas in excel 2007names vbamicrosoft excel lookup functionhow do you unhide in excelhow to unlock protected excel sheet without passwordmicrosoft excel create chartexample of excel worksheetvba array tutorialexcel formula to remove charactersexcel 2010 identify duplicatesmicrosoft excel tables tutorialcomplex macros in excelhow to colour duplicates in excelvbscript conditional statementsdata control language dclvba msgbox exampleexcel template project timelineusage of vlookup in excelhow to add the developer tab in excelsimple gantt chart template excel 2010range cells excel vbahow to use a pivot table excel 2010vba code to open a fileexcel vba formshow to use trim function in excelmerging cells in excel 2010example of a macro in excelhow to do vlookup in excel 2010 step by stepbeginners guide to vbapassword protect multiple excel filesexcel 2010 offset functionexcel macro syntaxexcel programming commandsexcel combine data from multiple worksheetsmod row excelvisual basics codesmsgbox iconexcel vba tipsvba datevaluemicrosoft office invoice templates for exceldynamic graph in excelexcel sample worksheetunprotect excel sheet onlineexcel formulas pdf in hindihlookup vbavlookup formula explanationhow to add command button in excelvba concatenate functionvba adodb recordset examplevisual basic excel 2007 tutorialvba guidevlookup tutorial in excelhow to duplicate a row in excelhow do you remove blank cells in excelalternative to vlookupexcel macro activate workbookvba workbooks openhow to cut and paste in excel