Microsoft Office Tutorials and References
In Depth Information
ListBox Techniques
For example, for a three-column list box, the ColumnWidths property might be set to
the following text string:
110 pt;40 pt;30 pt
5.
Specify the appropriate column as the BoundColumn property.
The bound column specifies which column is referenced when an instruction polls the
ListBox’s Value property.
To fill a ListBox with multicolumn data without using a range, you first create a two-dimensional
array and then assign the array to the ListBox’s List property. The following statements
demonstrate this using a 12-row x 2-column array named Data . The two-column ListBox shows the
month names in column 1 and the number of the days in the month in column 2 (see Figure
14-15). Notice that the procedure sets the ColumnCount property to 2 .
Private Sub UserForm_Initialize()
‘ Fill the list box
Dim Data(1 To 12, 1 To 2)
For i = 1 To 12
Data(i, 1) = Format(DateSerial(2010, i, 1), “mmmm”)
Next i
For i = 1 To 12
Data(i, 2) = Day(DateSerial(2010, i + 1, 1) - 1)
Next i
ListBox1.ColumnCount = 2
ListBox1.List = Data
End Sub
This example is available on the companion CD-ROM. The file is named listbox
multicolumn2.xlsm .
There appears to be no way to specify column headers for the ColumnHeads property
when the list source is a VBA array.
Figure 14-15: A two-column ListBox filled with data stored in an array.
 
Search JabSto ::




Custom Search