VBA Code to Add Items in ListBox Control in Userform

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

Leave a Reply

VBA Code to Sum Cells by Color
VBA Code to Sum Cells by Color

Recently some of our subscribers have requested us to share a VBA code that can sum the cells by its color. To help our subscribers and developers, we are sharing 2 codes that be used to sum the cells with specific color and returns the total sum of the matching color cells

VBA Tool to Track Start and End Time (Time & Motion Tracker)

Here is one more wonderful free tool from ExcelSirJi.com which makes your life easy. Time & Motion Tracker helps you to track Start and End time of any type of transaction or activity. The good thing is, it is VBA based tool which helps you to protect from manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time

VBA Code to Delete File
VBA Code to Delete File

In this article we are going to show you how you can delete file or files using a single line of VBA code. 1. Delete a specific file from the folder, 2. Delete specific type of files from the folder, 3. Delete all files from the folder


Like the Article? Please spread the word :)