VBA Code To Add Items In Listbox Control

Complete Excel VBA Course

Using ListBox in Userform is very common. You can use ListBox.AddItem function to add items in the listbox.; however, it is little difficult to add items in Listbox when the number of columns are more than one.

Here is a sample VBA code to help you
VBA Code to Add Items in ListBox Control in Userform
'Event handler to add list item in ListBox
Private Sub cmdSubmit_Click()
    
    'Add an item in the listbox
    lstDepartment.AddItem "Item Name"
    'If listbox has more than one column then add column value
    'Column 1
    lstDepartment.Column(1, lstDepartment.ListCount - 1) = "Item " & lstDepartment.ListCount
    'Column 2
    lstDepartment.Column(2, lstDepartment.ListCount - 1) = "Item " & lstDepartment.ListCount
    
End Sub
Commonly used ListBox properties
VBA Code to Add Items in ListBox Control in Userform
  • Name: Can be used to define control name
  • ColumnCount: Number of columns required in the listbox
  • ColumnHeads: Defines whether you want to show header or not
  • ColumnWidths: To change default Column width (e.g. 100 pt; 100 pt; 50 pt)
  • Enabled: To enable or disable the control
  • Height: To change height of the control
  • Locked: To lock or unlock the control
  • MultiSelect: To control the multiple selection options
  • SpecialEffect: To change the look and feel of the control
  • TabIndex: Tab index of the control
  • Visible: To hide or unhide the control
  • Width: To change the width of the control

Download Practice File

You can also practice this through our practice files. Click on the below link to download the practice file.

Recommended Articles

Excel VBA Course : Beginners to Advanced

We are offering Excel VBA Course for Beginners to Experts at discounted prices. The courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion

This course is going to help you to excel your skills in Excel VBA with our real time case studies.

Complete Excel VBA Course

Lets get connected and start learning now. Click here to Enroll.

Secrets of Excel Data Visualization: Beginners to Advanced Course

Here is another best rated Excel Charts and Graph Course from ExcelSirJi. This courses also includes On Demand Videos, Practice Assignments, Q&A Support from our Experts.

This Course will enable you to become Excel Data Visualization Expert as it consists many charts preparation method which you will not find over the internet.

So Enroll now to become expert in Excel Data Visualization. Click here to Enroll.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *