To set the properties of a
ListBox control so that the first row of data is used for the column labels in the list box, follow these steps:
- Close and save any open workbooks, and then open a new workbook.
- Type the following data in Sheet1:
A1: Name B1: Amount
A2: Bob B2: 1
A3: Sue B3: 2
A4: Tom B4: 3
A5: Pat B5: 4
- Start the Visual Basic Editor (press ALT+F11).
- In the Visual Basic Editor, click UserForm on the Insert menu.
- If the Toolbox is not visible, click Toolbox on the View menu. Click the List Box control in the Toolbox, and then draw a list box on the UserForm.
- In the Properties window, set the following properties for the ListBox control:
Property Value
--------------------------
ColumnHeads True
ColumnCount 2
RowSource Sheet1!A2:B5
- Run the UserForm. To do so, select the UserForm, and then click Run Sub/UserForm on the Run menu.
The labels in A1 and B1 are the column labels in the list box, and the
first row of selectable data is from A2 and B2.
NOTE: If you set the
RowSource property to "Sheet1!A1:B5" (without the quotation marks), and then run the UserForm, the data in A1 and B1 is a selectable row in the list box, and the column headings are "Column A" and "Column B," respectively.