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.
'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
Here we are coming with one more exciting post which can help you to solve very basic but very important problems while writing VBA codes.
VBA to Browse Outlook Folder Outlook is most commonly used emailing application used in the world. Many people spend their entire day on Outlook applications to read and respond to emails. To automate certain rule-based…
Did you come across any requirement where you want the user to interact with a sheet only through VBA Form? Here is a simple code which can help you.
Table of Content VBA Code to Get User Domain Name VBA Code to Get User Domain Name – Method 1 VBA Code to Get User Domain Name – Method 2 Steps to use this VBA…
How to Add Outlook Reference in Excel VBA? To automate Outlook based tasks from Excel you need to add Outlook Object Library (Microsoft Outlook XX.X Object Library) in Excel References. You can follow below steps…
VBA Code to Browse a Folder Quite often a VBA developer requires code to browse a folder. This is mainly for saving the output file or reading the input file(s). Below is the VBA code…