Listbox

 

Draw a Listbox    |   Add items to Listbox

An Excel VBA listbox, is a drop down list from where the user can make a choice. Learn how to draw a listbox on your worksheet and how to add items to a listbox.

Draw a Listbox

Excel 2010 and Excel 2007 users. Click on Insert from the Developer tab and then click on List Box in the ActiveX Controls section.

Create an Excel VBA Listbox in Excel 2010 or Excel 2007

Excel 2003 users. Click on List Box from the Control ToolBox.

Create an Excel VBA Listbox in Excel 2003

1. Draw a listbox on your worksheet.

Excel VBA Listbox Example

Add items to Listbox

To add some items to the listbox, execute the following steps.

1. Add the following code lines to the Workbook Open event (or add them to your own code).

With Sheet1.ListBox1
   .AddItem "Paris"
   .AddItem "New York"
   .AddItem "London"
End With


Note: use Sheet2 if your listbox is located on the second worksheet.

Result:

Add Code to the Workbook Open Event
2. To link a cell to the listbox, right click on the listbox (make sure design mode is selected) and click on Properties. Fill in D3 for LinkedCell.

Listbox LinkedCell

Note: also see the ListFillRange property, to fill a listbox with a range of cells.

3. Close Excel and reopen your Excel file.

Result:

Excel VBA Listbox Result

4. Note: if you use these code lines in your own code, outside the Workbook Open event, add the following code line at the start of your code.

ListBox1.Clear


This way your items won't be added multiple times, when you execute your code more than once.

Although in some situations it can be useful to directly place a listbox on your worksheet, a listbox is particularly useful when placed on a Userform.

Did you find this information helpful? Show your appreciation, vote for us.

Go to Top: Listbox    |   Go to Next Topic: Combobox

Learn more about listboxes, Login to the right >>
100 easy to follow Excel VBA examples. Limited time-offer: $39.00 but only $29.00. Ends on 31 May.