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

Similar Posts

Leave a Reply

Your email address will not be published.